I know that some functions are asynchronous, but how do you MAKE a function asynchrone? Do you use a timer? Or threads I guess?
Lets say I make a download class that has a downloadFinished event. I would create a class, and call it with the file destination. In the constructor it can start the download. But then code execution returns to the calling function. How is the downloadFinished event triggered?
Normally, you do the async part with notifications/observer. The problem usually is that the rest of your code is not async. Then you do the usual wait timer to get around that. If you can do the async part at the beginning of the code.
Nofification is a good idea.
I read that you should not do polling, so I guess that means no timer …
In many cases you can’t avoid polling. I have one case where I can’t poll - doing a diagnosis for Valentina at the end of adding data to a database. That caused the fun with the notifications I mentioned before.
or you can use addhandler in your other code to respond to the event being raised
I dislike addhandler and avoid it if I can as I consider it the modern equivalent of GoTo.
I think it is much preferable to pass a completionHandler to the long-running method.
Oh there are certainly other ways to achieve the same effect - a callback