在窗口服务的多个线程 [英] Multiple threads in windows service

查看:133
本文介绍了在窗口服务的多个线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows的项目和具有每5秒一个定时器的一种形式。

I have windows project and one form which have timer for each 5 seconds.

它调用并处理智慧请求指定表时间和条件明智的方法。

It calls and processes methods from request named table time wise and condition wise.

不过,我有一些方法类型这需要太多的时间作出反应,并希望在单独的线程这些方法。所以我可以运行在单独的线程同步和两个那些请求类型

But I have some methods types which takes too much time to respond and want those methods in separate thread. So that I can run those both request types in separate threads and syncs.

我该怎么办分离那些既采用螺纹 - 多线程异步

How can I do separate those both using thread -- multi async threads?

推荐答案

我建议你看看.NET 4.0 工作类。每次射击全螺纹可能是矫枉过正。任务,与定时器一起使用底层的线程池来并行执行的工作。

I recommend you look at the .NET 4.0 Task class. Firing full threads every time might be overkill. Tasks, together with timers use the underlying thread pool to execute work in parallel.

使用工作一样简单如:

Task t = Task.Factory.StartNew(
       () => 
       {
           // task code here
       });

这篇关于在窗口服务的多个线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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