开发者

How can I assign my method to a thread?

开发者 https://www.devze.com 2023-03-09 09:59 出处:网络
I have written the following code: var threaddatatable = new System.Threading.Thread(update); threaddatatable.Start(dt);

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

精彩评论

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