vendredi 13 mars 2015

How to use AutoResetEvent in WinForms

I recently found out about messaging between Threads in my application using AutoResetEvent. In a console app I would make a while(true) loop and rely on AutoResetEvent.WaitOne() to wait for a thread to signal that e.g. data is ready to be processed with AutoResetEvent.Set(). I know how to share data between threads using a Class that has a method for the worker thread, and data elements to share between the worker thread and the main thread.


My question is how to utilize AutoResetEvent in a Winforms app, where I normally don't see a command loop. Where should I put the WaitOne() call in a Winforms app?


About sample code: the best example is an answer on this site about how to make a Console.ReadLine() with a timeout, which is basically a straightforward example on how to use signals. That example is a console app example.


When googling, the answer on my question might be using the BackgroundWorker control ?


Aucun commentaire:

Enregistrer un commentaire