If you think your application does not need to perform calculations every time the ValueChanged event fires , you can use the DragCompleted Event in Thumb control to determine after the user has finished dragging and dropping the control.
<Slider Thumb.DragCompleted="Slider_DragCompleted_1" Height="27" Margin="132,162,0,0" VerticalAlignment="Top" Width="303"/>
When the user stopped dragging,
private void Slider_DragCompleted_1(object sender, DragCompletedEventArgs e) { Slider s = sender as Slider;
But be careful that this only works when the user drags the slider. This does not work when the user clicks on the slider.
Refer to this to handle other events such as mouse clicks, etc.
If you want to calculate with some time delay, you can use a timer.
EDIT: At your request, you can do this. In the event "ValueChanged".
// Start a new thread only if the thread is stopped // or the thread has not been created yet. if (threadPopular == null || threadPopular.ThreadState == ThreadState.Stopped) { threadPopular = new Thread(new ThreadStart(Your function)); threadPopular.Start(); }
Naren source share