❔ Calling async method
Hi guys. I tried to call this AzureAPI class in main program. But I got a error. I want to call this string Result in main program and display it.
How can I call this class and get a result in a place where I called.
21 Replies
It's not a static method
So it needs an instance to be called on
You need to create an object of AzureAPI so you can call the method
or convert the method to be static
I changed the method to static.
What does this mean?
it means the access level is restrictive, did you change the method to be private?
because your first screenshot showed it was public
Currently like this. But after I changed to static, string Result got the error.
public static async Task
You removed the public
for some reason
So it defaulted to private
apart from that, the Result property has to be static as well
Or... don't make it static
because from a static method you can only access another static members in the class
And instantiate the object
that's an easier approach I think
That way
Result
won't have to be static
And we'll have proper OOP
Instead of funky pseudo-global variables
Or, even better, just return the string from this method
Instead of using a propertyAfter changed Public static string Result, I got this error.
I want to display this string in textbox. I want to do it like this.
I recommend brushing up on the basics
What's
static
, what's an instance, etcI agree, I think you have to review the basics of C#, so you can make the proper changes for your code
if you have git enabled, you can undo your changes and apply this, to create an instance of the class
Two ways I can see it working
or
IMHO the first one is better
Ok guys. Thank you so much.
I will try this. Thank you
I called the method in main program. And got this. Do you guys know what that is and what I should do
not really, looks like the SpeechRecognizer class comes from a library and it is expecting to find something and fails?
I'm just guessing at this time, sorry
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.