Hello
Application.Restart(); not work in Task method
Closed Application but not run again Automaticly
What I have tried:
I Have this Code Block
<pre lang="c#">Task.Delay(ts).ContinueWith((x) =>
{
bool updateSuccess = checkUpdate2();
if (updateSuccess)
{
restart();
}
else
{
notifyIcon1.ShowBalloonTip(3000, "UPDATE", "No current updates found", ToolTipIcon.Info);
Thread.Sleep(3000);
}
});
public void restart()
{
try
{
this.scannerService.Stop();
this.travelDocumentScannerService.Stop();
this.printerService.Stop();
MessageBox.Show("Servisler Stopped");
this.mouseThread.Abort();
MessageBox.Show("Thread closed");
Thread.Sleep(3000);
Application.Restart();
}
catch (Exception ex)
{
var f = ApplicationDeployment.CurrentDeployment.DataDirectory +@"\RestartError.txt";
var err = "Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
"" + Environment.NewLine + "Date :" + DateTime.Now.ToString();
if (!File.Exists(f))
{
File.WriteAllText(f, err);
}
else
{
File.AppendAllText(f, err);
}
}
}
Everything run good but after call
Application.Restart();
Application closed and not run autotmaticly and dont give Exception too
if I run restart() method manual code work fine and restart Application but when it run in Task it doesnot work
where am I making a mistake