I have a process that calls an event when its done.
void DoProcess()
{
...
...
// Call finished event
OnFinished();
}
I want to run this process many times.
My first idea was to recall the process each time the ‘Finished’ event was called.
void obj_Finished()
{
DoProcess();
}
Would this mean that the stack would get bigger and bigger? since the ‘Finished’ event would call its self wich would call the ‘Finished’ event etc…
Could I use anouther thread in some way to avoid this problem?
Is there a better deisgn pattern that i coudl use?
I would like the code to be quite efficient, however, I do like using events 🙂
Assuming WinForms or WPF: Use a BackgroundWorker.
You can run DoProcess in a simple loop and call Updateprogress to execute your event (synchronized).
This assumes that DoProcess does not touch the UI, it is running on another thread. ProgressChanged runs on the Main thread.