June 29th, 2010, 03:29 PM
Patterns: What is the best way to ...
I'm trying to learn best programming practices here, I don't think this question is really language specific.
Nevertheless, I am developing in C#.
I'm trying to determine the best way to handle events *synchronously* as opposed to writing a ton of procs to handle different 'steps' that include multiple occurances of a given event.
execute code line 1
execute code line 2
execute code line 3
execute invoke code that will cause event and wait for event to occur
execute line 5
execute invoke more code that will cause event and wait for event.
execute line 7
etc. . .
Right now I'm using a loop that basically sits and waits for flags that I set just before invoking the event to change. The event proc resets the flags so I know when to break out of the loop. In the loop I use a System.Threading.Thread.Sleep(50); to keep it from overloading the CPU.
This just can't be the best way to do this.
For one thing, the 'sleep' keeps stopping 'sleeping' the code that needs to execute to trigger the event.
It works, but not very well.
Is there a proper way to accomplish what I'm after?
If so, what would be best programming practices for this?
June 29th, 2010, 04:21 PM
Re: Patterns: What is the best way to ...
I found your post to be a little confusing, but I believe what you are looking for is this
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!