bizarre behavior

  • Thread starter Thread starter dawn
  • Start date Start date
D

dawn

Hi,

I'm testing my app, and it does something very strange (at least i think so).
I have a button on my form and when I click it it triggers an event.
the method is structured like this

private void button3_click ( , )

{

if (timer1.Enabled)

{

timer1.Stop();

timer1.Enabled = false;

}

int count = 0

if (count < 5)

{

count++;

for ()

{

for()

{

//do a few things

}

}

timer1.Start();

timer1.Enabled = true;

}

else

{

//do some other things

}



}



Now when i test run the app......

count sometimes goes up to 5 (sometimes 4, other times 2).....without the code in Timer1_Tick ever being accessed, so it looks like button_3_click is executed more than once when the button is clicked. Nothing else in my code references to this method.

Why could it be doing this???



Any help will be greatly appreciated
 
Hi dawn,


Now when i test run the app......
count sometimes goes up to 5 (sometimes 4, other times 2).....without the
code in Timer1_Tick ever being accessed, so it looks like button_3_click is
executed more than once when the button is clicked. Nothing else in my code
references to this method.
Why could it be doing this???

Any help will be greatly appreciated


_tick event gets fired only when your app isn't doing anything because it is
in the same thread...
What are you trying to achieve?
 
yeah i know it only is supposed to be fired when my app isn't doing
anything....but that's the problem......my app shouldn't be doing a damn
thing....
the code i wrote is supposed to be doing this....
void
{
//do a few things
start timer
}
I don't have any code after the timer is started....so my app shouldn't be
doing something......only when i click the button......it seems the
click_button event gets fired numerous times instead of one

the basic idea of the timer was to have my app wait for a couple of seconds
before running other code.....without freezing my app.....so Thread.Sleep
wasn't an option.....and multi-threading didn't seem to be an option either
as it was far to complicated for the simple task of waiting a few seconds

the big problem now is......why does the button_click event get triggered
more than once
 
Hi down,
Are you sure you don't have registered more then once the event handler with
button's click event?
If you do so it will fire as many times as many times you have done
button.Click += new ..... Just for the test in the click event handler (when
the click event is fired) try to get event's invocation list
(GetInvocationList) and check how many event handlers you have registered.

HTH
B\rgds
100
 
Ok, it seems to have something to do with my mouse.....as long as my mouse
stays on top of the button.....the button_click event continues to get
fired....
that seems weird because i have only defined a click event for the button,
nothing like mouseover, mouseenter or anything like that......
when i use tab to go to the button and press enter.....the app works like
it's supposed to.....unless i have my cursor on top of the button....then it
does the same as if i were clicking the mouse (which i don't)
later in my code i do make some use of mouse_event, but it is not accessed
during this stage of the app, so i doubt this could be the reason.

Anyone have any clues???
 
100,

I'm afraid i can't do that....cuz when this is the only app i'm experiencing
that trouble in.
I just wrote a small form app that has one button on it....and when it gets
clicked it reports how many times the button was clicked...
I clicked on it with my mouse.....and it did as it was supposed to
do......"This button has been pressed 1 time(s)".
The other app seems to be the only one having the problem.....it has more
buttons on it.....and the strange behaviour occurs when any button is
clicked (i.e. the button_click related to the button that is clicked fires
as long as the cursor is over the button).
I suppose it could be a property in my other app.....but wouldn't have a
clue which one....i have never with another app encountered this problem.

Personally i don't have a clue to what might be wrong
 
Back
Top