本文介绍了如何让两个方法在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是Windows服务的新手,我正在尝试在Visual Studio 2012中创建。我想要两种方法继续运行在背景中并行/彼此断开连接。我怎样才能达到这个目的。一点点演示将受到高度赞赏。我的目标操作系统是Windows Server 2008 R2。请帮忙!
非常感谢您的预订!
Best此致,
Sunny
Hello everyone,
I''m new to Windows Service that I''m trying to create in Visual Studio 2012. I want two methods to keep running in background in parallel/disconnected from each other. How can I achieve this purpose. A little demonstration will be highly appreciated. My target OS is Windows Server 2008 R2. Please help!
Thanks a lot in Advance!
Best Regards,
Sunny
推荐答案
public void main()
{
...
bool run = true; // to control the exit from the loops
Task.Factory.StartNew(()=>{
while(run)
{
... // your code here
Thread.Sleep(10);// sleep for 10ms
}
});
}
这篇关于如何让两个方法在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!