开发者

How can I assign my method to a thread?

I have written the following code:

var threaddatatable = new System.Threading.Thread(update);
threaddatatable.Start(dt);

update(datatable dt)
{
}

But I am receivi开发者_运维知识库ng these errors:

The best overloaded method match for System.Threading.Thread.Thread(System.Threading.ThreadStart)has some invalid arguments

And

Argument 1 cannot convert from 'method group' to System.Threading.ThreadStart

How can I assign my update method to my thread?


The signature takes object; you need

new Thread(obj => update((DataTable)obj));

I also suggest looking at either the ThreadPool or TPL/Task - threads are relatively expensive.


you should rewrite your code like this

var threaddatatable = new System.Threading.Thread(new System.Threading.ThreadStart( update)); threaddatatable.Start();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜