PeekMessage/GetMessage switching in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JR

    PeekMessage/GetMessage switching in C#

    Hi folks,

    How can I implement the following in C#?

    while(AppExitFl ag == false)
    {
    if(AppPausedFla g == true)
    {
    GetMessage();
    // Process messages.
    }
    else
    {
    if(PeekMessage( ))
    {
    // Process messages.
    }

    // Do stuff...
    }
    }

    I have a feeling you're gonna tell me this is impossible, I hope you tell me
    I'm wrong. :-)

    John.


  • JR

    #2
    Re: PeekMessage/GetMessage switching in C#

    Hi folks,

    Heh, typical as soon as I write this I think of a solution:

    OnApplicationId leEvent()
    {
    while(AppPaused Flag == false)
    {
    // Do stuff.
    Application.DoE vents();
    }
    }

    static void Main()
    {
    Application.Run (new Form1());
    }

    This seems to work... Caveats anyone?

    John.

    "JR" <moo> wrote in message
    news:3ff9df10$0 $9392$cc9e4d1f@ news-text.dial.pipex .com...[color=blue]
    > Hi folks,
    >
    > How can I implement the following in C#?
    >
    > while(AppExitFl ag == false)
    > {
    > if(AppPausedFla g == true)
    > {
    > GetMessage();
    > // Process messages.
    > }
    > else
    > {
    > if(PeekMessage( ))
    > {
    > // Process messages.
    > }
    >
    > // Do stuff...
    > }
    > }
    >
    > I have a feeling you're gonna tell me this is impossible, I hope you tell[/color]
    me[color=blue]
    > I'm wrong. :-)
    >
    > John.
    >
    >[/color]


    Comment

    • Chris Taylor

      #3
      Re: PeekMessage/GetMessage switching in C#

      Hi,

      The only change I would make to your code is to remove the while loop and
      thus the requirement to call Application.DoE vents(), this would I believe be
      more friendly to the primary message pump.

      OnApplicationId leEvent()
      {
      if (AppPausedFlag == false)
      {
      // Do stuff.
      }
      }

      If you want the system to be more responsive, especially if your Dostuff
      takes significant amount of processing time, it might be an option to create
      a background thread to perform the work. And you can control the thread with
      synchronization objects.

      Hope this helps

      --
      Chris Taylor

      "JR" <moo> wrote in message
      news:3ff9e1c6$0 $9392$cc9e4d1f@ news-text.dial.pipex .com...[color=blue]
      > Hi folks,
      >
      > Heh, typical as soon as I write this I think of a solution:
      >
      > OnApplicationId leEvent()
      > {
      > while(AppPaused Flag == false)
      > {
      > // Do stuff.
      > Application.DoE vents();
      > }
      > }
      >
      > static void Main()
      > {
      > Application.Run (new Form1());
      > }
      >
      > This seems to work... Caveats anyone?
      >
      > John.
      >
      > "JR" <moo> wrote in message
      > news:3ff9df10$0 $9392$cc9e4d1f@ news-text.dial.pipex .com...[color=green]
      > > Hi folks,
      > >
      > > How can I implement the following in C#?
      > >
      > > while(AppExitFl ag == false)
      > > {
      > > if(AppPausedFla g == true)
      > > {
      > > GetMessage();
      > > // Process messages.
      > > }
      > > else
      > > {
      > > if(PeekMessage( ))
      > > {
      > > // Process messages.
      > > }
      > >
      > > // Do stuff...
      > > }
      > > }
      > >
      > > I have a feeling you're gonna tell me this is impossible, I hope you[/color][/color]
      tell[color=blue]
      > me[color=green]
      > > I'm wrong. :-)
      > >
      > > John.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...