Reputation: 11285
could you tell a beginner why this small WPF-application is not closing as intended after the WorkflowTerminated event fires? The used workflow just terminates immediately. (using a WPF application, .Net Framework 3.5)
public partial class MainWindow : Window
{
private WorkflowRuntime wfRuntime = new WorkflowRuntime();
public MainWindow()
{
InitializeComponent();
wfRuntime.WorkflowTerminated += (se, ev) => this.Close(); // this doesn't close the window
wfRuntime.WorkflowCompleted += (se, ev) => this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
WorkflowInstance launcherWorkflow = wfRuntime.CreateWorkflow(typeof(InstallerWorkflow));
launcherWorkflow.Start();
}
}
Upvotes: 5
Views: 3735
Reputation: 25742
Probably because the callback is on another thread. A basic workaround is to terminate the application altogether using Environment.Exit(1);
To call the close function on the UI thread you should use:
wfRuntime.WorkflowTerminated += (se, ev) => {
// call back to the window to do the UI-manipulation
this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
{
this.Close();
}));
};
Upvotes: 6