how to keep a windows application alive in C#?

≯℡__Kan透↙ 提交于 2019-12-25 19:40:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!