如何在 C# 中保持 Windows 应用程序的活动状态? [英] how to keep a windows application alive in C#?

查看:48
本文介绍了如何在 C# 中保持 Windows 应用程序的活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主函数中有一个包含以下代码的应用程序:

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));

var timer = new System.Threading.Timer(Callback_f, null, TimeSpan.Zero, TimeSpan.FromMinutes(srcInterval));

好吧,这确实有效,但只有当我放置一些东西来保持我的应用程序存活时,例如 console.readkey() 或无限 while 循环:

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) 
{

}.

无限循环对我来说不是一个选择,因为它太耗时了.问题是我不能使用 console.readkey 函数,因为它是一个 Windows.forms 应用程序,其中没有表单.(即,当我将它作为控制台应用程序运行并在最后放置一个 console.readkey() 方法时,它可以工作.但是我想避免显示黑色窗口,它是一个没有界面的应用程序在后台运行).有什么建议吗?

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?

推荐答案

尝试使用方法 Thread.Join();

这篇关于如何在 C# 中保持 Windows 应用程序的活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆