问题
I have an application with the following code in my main function:
var timer = new System.Threading.Timer(Callback_f, null, TimeSpan.Zero, TimeSpan.FromMinutes(srcInterval));
Okay this actually works but ONLY when I put something to keep my application alive like console.readkey()
or an infinite while loop:
while (true)
{
}.
The infinite loop is not an option for me as it is too time consuming. The thing is I can not use the console.readkey
function either because it's a Windows.forms application with no forms in it. (i.e. when I run it as a console application and put a console.readkey()
method at the end it works. However I want to avoid the showing of the black window, it's an application with no interface which runs in the background). Any suggestions?
回答1:
try to use method Thread.Join();
来源:https://stackoverflow.com/questions/14014165/how-to-keep-a-windows-application-alive-in-c