Button click event handler not called.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm working on a C# application, in VS.NET 2003. The part that I'm currently
having trouble with is a single form, whose message loop runs in a separate
thread from the application's main GUI. This form provides an interface
which allows the user to send a series of string messages over a socket, to
another thread in the same application. Some messages require a response,
and some don't. But when every message is processed, it gets logged to a
DataGrid on the same form. The form has a "Send" button, which processes all
the specified messages, and an "Abort" button, to allow the user to abort the
sequence.

I set up a click event for both buttons, using the form designer. If I
press "Abort" when the program is idle or waiting for a response over the
socket, the click handler gets called, as normal. But, if the program is
actively sending messages that do not require it to wait very long for a
response, then clicking the Abort button only causes it to LOOK like it got
pressed, but the click handler is not called.

I added MouseUp and MouseDown handlers for that button and saw that both
handlers are getting called EVERY time I press the button, even when the
click handler is NOT called. The obvious kludge is to dispense with the
click handler and use MouseDown, instead, but I am curious why the problem is
occurring.

In order to keep the UI responsive and to allow the other threads to run, I
use a timer. Also, as messages get logged, I set the CurrentCell property on
the DataGrid, in order to make it scroll to the bottom. This forces that
control to get redrawn quite frequently. It is quite likely that these timer
tick and redraw events get inbetween the MouseDown and MouseUp events.

Could that prevent Windows from calling the click handler?

Thanks,
Dave

.


Quantcast