how to keep a windows application alive in C#?

2019-09-25 12:01发布

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条回答
可以哭但决不认输i
2楼-- · 2019-09-25 12:07

try to use method Thread.Join();

查看更多
登录 后发表回答