我有这个功能static void appUpdater(string appName, string proccessName){ /**/}我需要为每个应用程序更新创建一个线程,但 ThreadStart 和 ParameterizedThreadStart 与委托不匹配Thread wms = new Thread(new ParameterizedThreadStart(appUpdater));wms.Start("WMS","StuMenu");
2 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
你不能。Thread.Start()只接受一个类型的参数object。但是您可以例如传递自定义对象或字典
目的:
class ThreadParameters {
public string p1 {get;set;}
public string p2 {get;set;}
}
static void appUpdater(object p) {
ThreadParameters tp = p as ThreadParameters;
}
Thread wms = new Thread(new ParameterizedThreadStart(appUpdater));
wms.Start(new ThreadParameters{p1="p1", p2= "p2"});
字典:
static void appUpdater(object p) {
Dictionary<string, object> tp = p as Dictionary<string, object>;
}
Thread wms = new Thread(new ParameterizedThreadStart(appUpdater));
wms.Start(new Dictionary<string, object>{{"p1", "p1"}, {"p2", "p2}});
但根据您的需求,aTask可能是更好的方法。
- 2 回答
- 0 关注
- 191 浏览
添加回答
举报
0/150
提交
取消