Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

timer - how to keep a windows application alive in C#?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try to use method Thread.Join();


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...