Good people.
I have a small problem, I have a Window to serve only to send information to the user to say what is happening in Background, but sometimes the code runs fast and more and he does the close before opening the window. Remember that this is in WPF and not in WinForm, you do not want to pass as .Show(this)
Here is the code to do this:
var windowWaitForWorker = new WindowWaitForWorker("Informação", "Aguarde por favor")
{
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Owner = GetWindow(this)
};
await Task.Run(new Action(() =>
{
Application.Current.Dispatcher.InvokeAsync(new Action(() =>
{
windowWaitForWorker.ShowDialog();
}));
try
{
if (!File.Exists(System.IO.Path.Combine(GlobalVars.DIR_MAIN, "info.dat")))
{
stateOfStartApp = 1;
}
else
{
}
}
catch (Exception ex)
{
errorOnTaskRun = true;
GlobalFunc.WriteToLog("[" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "] MainWindow-StartOfProgram\r\n" + ex.Message);
}
}));
windowWaitForWorker.Close();
To make more sense, I have this in a Thread the part, because if the file exists AKA the information of the database, is to do several checks, load information and the like, if not, is to open a window to be by the information from the database and only then will do the rest.
I also intend to use this same algorithm for other things, which may be fast or it may take a while, so I'll be ready to do it.
Remember that if I call ShowDialog()
before await Task.Run
it will never go down unless the window is closed