how to set FinishButtonEnabled for long running finish task

Wizard for WPF Forum

Posted 14 years ago by Rod Kuhns
Avatar
When user presses Finish Button, I have a task that takes some time to run. I would like to set the Finish Button to a disabled state once finish is pressed while the long task is performed to prevent user from pressing it several times, not knowing if thier first button press did anything. Using the following code the button does not change to a disabled state prior performing the task in wizard_Finish.


private void wizard_PreviewFinish(object sender, RoutedEventArgs e)
{
wizard.FinishButtonEnabled = false;
this.Cursor = Cursors.Wait;
wizard.InvalidateVisual(); //attempt at getting button to draw as disabled
}

private void wizard_Finish(object sender, RoutedEventArgs e)
{
//perform long running task...
NewProjectWizardViewModel.Instance.ProjectSaveRequested = true;
}

The wait cursor does get displayed. How do I get the Finish Button to display as non-Enabled while the wizard_Finish task runs?

Thank you for any suggestions!

Rod



ActiproSoftware.Wizard.Wpf30 Reference Properties:
Runtime Version: v2.0.50727
Version: 9.2.511.0

[Modified at 05/06/2010 09:47 AM]

[Modified at 05/06/2010 03:22 PM]

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Rod,

The WPF rendering code is probably not kicking in by the time the Finish event first. You may have to do a Dispatcher.BeginInvoke call on your long-running task at a low priority to allow the rendering to complete. BeginInvoke would queue up your task after rendering that way.


Actipro Software Support

Posted 14 years ago by Rod Kuhns
Avatar
Thank you! That solved it. Here is the code I ended up with:

private void wizard_PreviewFinish(object sender, RoutedEventArgs e)
{
NewProjectWizardViewModel.Instance.FinishEnabled = false;
this.Cursor = Cursors.Wait;
}

private void wizard_Finish(object sender, RoutedEventArgs e)
{
Dispatcher.Invoke(DispatcherPriority.Background,
(ThreadStart)delegate
{
//long running task
NewProjectWizardViewModel.Instance.ProjectSaveRequested = true;
});
}


The ViewModel stuff is specific to our implementation and not needed for this result. The answer was invoking the long running task using dispatcher at a lower priority as was suggested by Actipro Support above.
The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.