U
U
Uran_902015-12-29 11:22:23
.NET
Uran_90, 2015-12-29 11:22:23

Why won't the WPF dialog open?

The essence of the problem is this: In a dialog, in a parallel thread, the execution of a stored procedure is called. The execution takes about 20 minutes, because slow connection at the database server. At run time, I close the dialog and interrupt the thread. After that, I try to start the dialog again (a new instance is created), but the dialog does not open (although the OnInitialized and OnActivated methods are fired).
Code:
MainWindow
{
...
private void OnImport()
{
var frm = new SAPImportParametersWindow(DoEndImport, DoBeginImportByURL);
frm.Owner = MainWindow.Instance;
frm.ShowDialog();
frm.Close();
}
private int DoBeginImportByURL(string connectionString)
{
...
callSqlProcedure();// execute time ~ 20 min
...
}
...
}
Dialog : Window
{
...
private void buttonOk_Click()
{
...
backgroundWorker.DoWork += delegate
{
DoBeginImportByURL(connectionString);
}
...
DialogResult = true;
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
backgroundWorker.CancelAsync();
_sAPImportDataEndDelegate = null;
_sAPImportDataByURLBeginDelegate = null;
DialogResult = false;
}
...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2015-12-29
@Sumor

In general, just because you closed the dialog does not mean that your lengthy operation has been interrupted.
backgroundWorker.CancelAsync(); just informs the task that it is being interrupted. Inside the backgroundWorker handler, there should be a special check for the CancellationPending property, which, when set, should exit the processing thread.
Closing the form does not destroy the thread with the task - it will be executed until it reaches the end.
Most likely, when you reopen the form, you have a conflict with resources that are already being used by the first processing thread.
Looking further, if you are performing a long-running operation on the server, such as a long-running stored procedure, then even closing the application that launched this stored procedure does not guarantee that the process on the server will stop. Especially if the process changes the data. Depending on the logic of the server, the process may continue to the bitter end, it may be interrupted at some key moment, or it may go into a long rollback of changes to bring everything to the state before the storage was launched.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question