While Loops and Keyboard Events

In a class I have a while loop that sends out an event while test is true as follows:

while(test)
{
      PeriodFire(this, new PeriodEventArgs(true));

}

In another class I consume the event and do some graphical work on it.

this.timer1.PeriodFire += new ABIS.PeriodEventHandler(TimerOnTick);

public void TimerOnTick()
{
   .... Do some graphical work
   Application.DoEvents();
}

I am also using the keyboard Events KeyDown() and KeyPress() to do some work.

The problem I am having is that the keyboard events are not being fired. Or if they are, it is only once now and then.

Any suggestions on why would be appreciated.

with regards



Answer this question

While Loops and Keyboard Events

  • burrowsUW

    Rather than a different thread, I implemented a line in the TimerOnTick method to 

    stop the periodFire event and then started it again after the graphics work, but that
    didn't seem to alter anything.
    as follows:


    this
    .timer1.PeriodFire += new ABIS.PeriodEventHandler(
    TimerOnTick);

    public void TimerOnTick()
    {
       stop event fire
       .... Do some graphical work
       Application.DoEvents();
       start event fire
    }




  • Luis Simões

    Looks like your app doesn't get enough time to process its message queue. 

    This graphical work - is it time consuming   If so, it may be advisable to take it to a different thread.

  • Project Ebiru

    ok, I had tried a thread, but on the wrong method.  I thought I could thread the TimerOnTick() method, but ends up I need to thread the while loop method.

    Hope this is useful to whoever comes across this.

    cheers.

  • Mike Ogilvie

    I think I may have spoken to soon. I am substantiating 5 objects based on the one
    class that has the TimerOnTick method(ie this method does the graphics work). I have implemented
    a thread safe method in the class to update the form. However, when I run my application that runs all of these
    at the same time I get a lot of flicker in them as though there is an interupt from somewhere.



  • While Loops and Keyboard Events