Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I need to increase my property value every 500ms IF button is pressed/down.

Here is example code snippet

XAML
<Button Height="50" Width="100" Content="PressMe" MouseDown="Button_MouseDown"></Button>


private void Button_MouseDown(object sender, MouseButtonEventArgs e)
       {
           Value = Value + 1;
           System.Threading.Thread.Sleep(500);
       }



The problem is that my event never fires up. If I create mouseClick event in xaml it fires up, but doest fit my needs.

Hope you got my idea :)

Cheers!
Posted
Comments
Laurence1234 20-Dec-10 9:27am    
Do you mean you want your value to be continuously increased once the button is pressed, every 500ms or just once with single pause of 500ms?

1 solution

You probably need to create a thread on the ButtonDown event, and abort that thread on the ButtonUp event.

The thread will sit/spin until aborted, and every 1/2 second (or the interval you specify), the target value is increased.

If it were me, I'd use a BackgroundWorker object as my thread processing because it's easily cancellable from outside the object.
 
Share this answer
 
v2
Comments
paleGegg0 20-Dec-10 11:19am    
Thank you so much! That helped a lot :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900