+ 1
Terminate app after 2 second delay
Hi everybody, anybody knows how can i terminate app after 2 second in c#?(which method shall i use ?) for example if user entered wrong number , the program's going to be terminated after 2second.
5 Respostas
+ 4
Try this:
Console.WriteLine("Hello, world!");
System.Threading.Thread.Sleep(2000);
Environment.Exit(0);
Note that this may not work on CodePlayground. Pretty sure CodePlayground won't show these delays.
+ 2
hm.
Do you want the program to be responsive during the delay?
If not, you can use Thread.sleep(2000);
That will basically pause the program for 2000 milliseconds (2 seconds).
So you could do some pop up like "closing the app". Then pause it for 2secs then quit.
Then, you can use something like Application.exit();
or Environment.exit.
https://stackoverflow.com/questions/12977924/how-to-properly-exit-a-c-sharp-application
+ 1
this works fine, i tried it, thanks
0
i want the program to run like this:
Console.WriteLine("Sorry you entered wrong numbers more than twice")
and then want to terminate app after 2 second because i wanna give time to user to read the message before the program goes shut down!
0
i tried this one;
Task.Delay(2000);
Enviroment.Exit(0);
but it didn't work