I would like to achieve this:
- Create a new window, which is just a spinning loader and some static text, and display it.
- Do some computation on the UI thread (it has to be done there)
- Close the loader window
Currently, when I call .Show() on the loader window, it doesnt load at all, it just hangs out as a blank window (the UI thread is blocked, which I dont want)
What can I do to enable the loader window to display its contents at the same time my computation is done?
private void CopyToClipboard(object sender, RoutedEventArgs e)
{
var selected = mDataGrid.SelectedItem;
var selectedIndex = mDataGrid.SelectedIndex;
var progressWindow = mProgressDialog.Create(this,"Copying data to clipboard");
progressWindow.Show();
try
{
mDataGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
mDataGrid.SelectionMode = DataGridSelectionMode.Extended;
mDataGrid.SelectAllCells(); // SLOW !!!!
ApplicationCommands.Copy.Execute(null, mDataGrid); //SLOW !!!!
}
catch (Exception ex)
{
mLog.Error("Copying to clipboard", ex);
MessageBox.Show("Error while copying to clipboard");
}
finally
{
mDataGrid.SelectionMode = DataGridSelectionMode.Single;
mDataGrid.UnselectAllCells();
this.Select(selectedIndex, selected);
progressWindow.Close();
}
}