I start my form in the usual way:
Application.Run(new MainForm());
I want it to open and run before a certain time, and then close. I tried the following, but to no avail:
(1) In the main method (there was an expression Application.Run ()), I enter the following AFTER Application.Run ()
while (DateTime.Now < Configs.EndService) { }
RESULT: he never hits.
(2) BEFORE STARTING Application.Run () I am launching a new background theme:
var thread = new Thread(() => EndServiceThread()) { IsBackground = true };
thread.Start();
where EndServiceThread:
public static void EndServiceThread()
{
while (DateTime.Now < Configs.EndService) { }
Environment.Exit(0);
}
RESULT: vshost32.exe has stopped working with a failure.
(3) In the MainForm Tick event:
if (DateTime.Now > Configs.EndService)
{
this.Close();
}
RESULT: vshost32.exe has stopped working with a failure.
What is the right way to achieve my goal? Again, I want to run the form, open it and run until a certain time (Configs.EndService), and then close.
Thanks Ben.
source
share