D
David
I am trying to get this straight in my head so I can implement.
I wrote a small utility some time ago in c# that utilized a handful of
threads. That scenario was one main thread manually spawning a handfull of
worker threads, then waiting for all of them to complete before moving on. I
believe I used array of ManualResetEvents and the WaitAll() method to do
this. All the worker threads used a shared object (a common place to
collect and output data). I recall having to use 'lock' (essentially the
monitor class) to synchronize access to this object. All works great. That
was a while ago and now I have a new scenario (much simpler, I think) but I
can't get a solution straight in my head. I'm using this past example
because it is my only point of reference for mutlithreaded scenarios.
now, I'm writting a small utility (console app) that is using the asynch
programming pattern. I simply want the main thread to show some kind of
progress indicator (writing dots to screen, whatever) after calling an
asynch method and then move on after asnych operation completes. So
currently the code is structured so that the asynch operation is started and
the main thread just waits using WaitOne() until the asynch operation
signals the manualResentEvent. Now I want to implement the progress
indicator but I'm not sure how. I'm assuming I need to get rid of the
manualResetEvent and waitOne() setup and move to checking some variable that
both threads have access to?
while (sharedVar) {do progress indicator thing}
Based on what I learned from the older project I described, I immediately
thought to just use lock. But then I thought that the lock would never be
released from the progress indicator loop in order for the other thread to
gain the lock and modify the sharedVar so the loop could end?
any input on how I should be handling this scenario would be greatly
appreciated.
I wrote a small utility some time ago in c# that utilized a handful of
threads. That scenario was one main thread manually spawning a handfull of
worker threads, then waiting for all of them to complete before moving on. I
believe I used array of ManualResetEvents and the WaitAll() method to do
this. All the worker threads used a shared object (a common place to
collect and output data). I recall having to use 'lock' (essentially the
monitor class) to synchronize access to this object. All works great. That
was a while ago and now I have a new scenario (much simpler, I think) but I
can't get a solution straight in my head. I'm using this past example
because it is my only point of reference for mutlithreaded scenarios.
now, I'm writting a small utility (console app) that is using the asynch
programming pattern. I simply want the main thread to show some kind of
progress indicator (writing dots to screen, whatever) after calling an
asynch method and then move on after asnych operation completes. So
currently the code is structured so that the asynch operation is started and
the main thread just waits using WaitOne() until the asynch operation
signals the manualResentEvent. Now I want to implement the progress
indicator but I'm not sure how. I'm assuming I need to get rid of the
manualResetEvent and waitOne() setup and move to checking some variable that
both threads have access to?
while (sharedVar) {do progress indicator thing}
Based on what I learned from the older project I described, I immediately
thought to just use lock. But then I thought that the lock would never be
released from the progress indicator loop in order for the other thread to
gain the lock and modify the sharedVar so the loop could end?
any input on how I should be handling this scenario would be greatly
appreciated.