Hi Bill,
Maybe i don't understand your problem?
If i run form in [STAThread] mode, my events are fired in
queue as they were started.
Try this code (after placing ListBox control on your form):
private void LongTimeNothing() {
int i,j,k;
int maxVal=400;
for(i=0; i<maxVal; i++) {
for(j=0; j<maxVal; j++) {
for(k=0; k<maxVal; k++) {
int val=i+j+k;
}
}
}
}
private void listBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs ea) {
listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar));
this.LongTimeNothing();
listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar));
}
private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs ea) {
listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button));
this.LongTimeNothing();
listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button));
}
....then set listBox1 events for "KeyPress" & "MouseDown" to
proper methods in code
Regards
Marcin Grzêbski
[quoted text, click to view] Bill Henning wrote:
> Does anyone know a good method of preventing keyboard and mouse events from
> interrupting processing?
>
> My situation is:
> 1) I need to track and handle all key and mouse events
> 2) I need to perform processing on certain key/mouse events
> 3) If key/mouse events interrupt processing, the events should not be
> discarded since they need to be handled but AFTER the current processing is
> complete
>
> Right now, if I press 3 keys really fast and track console messages (to know
> what sequence of code executes) I get something like this:
> * OnKeyPress(a)
> * ProcessingStart(a)
> * OnKeyPress(b)
> * ProcessingStart(b)
> * OnKeyPress(c)
> * ProcessingStart(c)
> * ProcessingEnd(c)
> * ProcessingEnd(b)
> * ProcessingEnd(a)
>
> Where this is what I need but don't know how to make happen:
> * OnKeyPress(a)
> * ProcessingStart(a)
> * ProcessingEnd(a)
> * OnKeyPress(b)
> * ProcessingStart(b)
> * ProcessingEnd(b)
> * OnKeyPress(c)
> * ProcessingStart(c)
> * ProcessingEnd(c)
>
> Any help is MUCH appreciated!
>
> Bill
>
>
Marcin,
I think you're right... I looked over my huge amount of processing code and
found an Application.DoEvents(). When I took that out, it started working
again sequentially as it should. I've learned my lesson with not to use the
DoEvents! :)
Thanks,
Bill
[quoted text, click to view] "Marcin Grzêbski" <mgrzebski@stop.spam.taxussi.com.pl> wrote in message
news:beeboq$rc2$1@nemesis.news.tpi.pl...
> Hi Bill,
>
> Maybe i don't understand your problem?
> If i run form in [STAThread] mode, my events are fired in
> queue as they were started.
>
> Try this code (after placing ListBox control on your form):
>
> private void LongTimeNothing() {
> int i,j,k;
> int maxVal=400;
> for(i=0; i<maxVal; i++) {
> for(j=0; j<maxVal; j++) {
> for(k=0; k<maxVal; k++) {
> int val=i+j+k;
> }
> }
> }
> }
>
> private void listBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs ea) {
> listBox1.Items.Add(String.Format("KeyPress for \'{0}\'",
ea.KeyChar));
> this.LongTimeNothing();
> listBox1.Items.Add(String.Format("KeyPress for \'{0}\'",
ea.KeyChar));
> }
>
> private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs ea) {
> listBox1.Items.Add(String.Format("MouseDown for \'{0}\'",
ea.Button));
> this.LongTimeNothing();
> listBox1.Items.Add(String.Format("MouseDown for \'{0}\'",
ea.Button));
> }
>
> ...then set listBox1 events for "KeyPress" & "MouseDown" to
> proper methods in code
>
> Regards
>
> Marcin Grzêbski
>
> Bill Henning wrote:
>
> > Does anyone know a good method of preventing keyboard and mouse events
from
> > interrupting processing?
> >
> > My situation is:
> > 1) I need to track and handle all key and mouse events
> > 2) I need to perform processing on certain key/mouse events
> > 3) If key/mouse events interrupt processing, the events should not be
> > discarded since they need to be handled but AFTER the current processing
is
> > complete
> >
> > Right now, if I press 3 keys really fast and track console messages (to
know
> > what sequence of code executes) I get something like this:
> > * OnKeyPress(a)
> > * ProcessingStart(a)
> > * OnKeyPress(b)
> > * ProcessingStart(b)
> > * OnKeyPress(c)
> > * ProcessingStart(c)
> > * ProcessingEnd(c)
> > * ProcessingEnd(b)
> > * ProcessingEnd(a)
> >
> > Where this is what I need but don't know how to make happen:
> > * OnKeyPress(a)
> > * ProcessingStart(a)
> > * ProcessingEnd(a)
> > * OnKeyPress(b)
> > * ProcessingStart(b)
> > * ProcessingEnd(b)
> > * OnKeyPress(c)
> > * ProcessingStart(c)
> > * ProcessingEnd(c)
> >
> > Any help is MUCH appreciated!
> >
> > Bill
> >
> >
>