Patterns: What is the best way to ...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Patterns: What is the best way to ...

  1. #1
    Join Date
    Jun 2010
    Posts
    1

    Patterns: What is the best way to ...

    Hi:

    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.

    Example:
    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?

  2. #2

    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

    http://msdn.microsoft.com/en-us/libr...aithandle.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center