网站首页
网站导航
Ctrl+D收藏
首 页
代码段
源码包
文档库
工具箱
代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
一个线程实时监控类
作者:
/ 发布于
2018/1/29
/
328
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace { public class AutomateThread { public static Thread StartNew(ThreadStart start) { Thread t = new Thread(start); t.Start(); return t; } public static Result Monitor(int nTimeOutMS, ThreadStart start) { Stopwatch sw = Stopwatch.StartNew(); Thread t = AutomateThread.StartNew(() => { start(); }); while (sw.ElapsedMilliseconds < nTimeOutMS) { if (!t.IsAlive) { return new Result(true, false); } else { Thread.Sleep(30); } } return new Result(false, true); } public static Result MonitorAll(int nTimeOutMS, params ThreadStart[] threadStart) { Stopwatch sw = Stopwatch.StartNew(); IList<Thread> threads = new List<Thread>(); bool bFinish; foreach (var item in threadStart) { var t = AutomateThread.StartNew(item); threads.Add(t); } while (sw.ElapsedMilliseconds <= nTimeOutMS) { bFinish = true; foreach (var item in threads) { if (item.IsAlive) { Thread.Sleep(30); bFinish = false; } } if (bFinish) { return new Result(true, false); } } return new Result(false, true); } public static void WaitAll(params Thread[] threads) { Stopwatch sw = Stopwatch.StartNew(); foreach(Thread t in threads) { while(t != null && t.IsAlive) { Thread.Sleep(30); } } } } }
评论列表
本站所提供的代码,版权归原作者所有,若有侵犯作者版权,请与我们联系,我们将立即删除或修改。谢谢!
本站所有代码发布及提供者。
试试其它关键字
同语言下
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
.
计算每周和每月固定日期
可能有用的
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
.
计算每周和每月固定日期
贡献的其它代码
Label
地图
本站
我们
服务
版权
联系
回馈
博客