Answer the question
In order to leave comments, you need to log in
How to prevent multiple button clicks? WPF?
There is a button, when pressed, a long operation takes place, at the end of which the rendering of the image/ element is affected.
The element image.Source = new DrawingImage(dGroup); dGroup contains drawingVisual elements that are removed and added during the click function.
The problem is if I click 10 times then it will do the calculations 10 times. And I don’t understand how to stop them at all.
By debugging, all click events are queued and executed one after another, but Animation works, as I understand it, in another thread. How to disable processing while image is being redrawn?
This is the kind of thing that doesn't work.
private void solveClick(object sender, EventArgs e)
{
if (!((Button)sender).IsEnabled) // пробoвал по таймеру, не помoгает, все вызовы
return;
else
{
((Button)sender).IsEnabled = false;
var selectedTabItem =(TabItemInterface) (this.TabsFunc.SelectedItem);
if (selectedTabItem.IsReady())
{
selectedTabItem.Calculate( ); // в конце вычислений обновляет содержимое DawingGroup
// this.UpdateLayout();
((Button)sender).IsEnabled = true;
}
}
}
Answer the question
In order to leave comments, you need to log in
On click - disable the button [and possibly other related ui elements + unlock / show others] and then run something long in a separate thread .. upon its completion - unlock.
Classic: two buttons "start" and "stop" + progressbar
IsEnabled for buttons clings to the boolean field IsProcess (inversely for start and right for stop)
ProgressBar - visible only when IsProcess == true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question