This is a simple way to restart your application at predefined time of a day.
in this example Im gonna restart my application everyday at 6 o'clock morning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DispatcherTimer timer = new DispatcherTimer(); | |
private void RestartMyApplication() | |
{ | |
timer.Interval = TimeSpan.FromSeconds(1.0); | |
timer.Start(); | |
timer.Tick += new EventHandler(delegate(object s, EventArgs a) | |
{ | |
if (DateTime.Now.ToString("hh:mm:ss tt") == "06:00:00 AM") | |
{ | |
//start new application | |
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); | |
Environment.Exit(0); //exit this application | |
} | |
}); | |
} |
Enjoy !!!
No comments:
Post a Comment