Click here to Skip to main content
15,898,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var threaddatatable = new System.Threading.Thread(update);
threaddatatable.Start(dt);

update(datatable dt)
{
}


i will be write this code it will be shown the errors

1.The best overloaded method match for System.Threading.Thread.Thread(System.Threading.ThreadStart)has some invalid arguments <br />
<br />
2.Argument 1 cannot convert from method group to System.Threading.ThreadStart; <br />

thanks in advance
Posted
Updated 28-May-11 3:19am
v2
Comments
#realJSOP 28-May-11 9:19am    
Fixed your code formatting

Using ParameterizedThreadStart is bad, because it forces you into type case.
This is much better way of passing parameters into a thread and solving any similar problems — creating a thread wrapper which would automatically pass the instance of the class via "this".

Code sample is very simple:
How to pass ref parameter to the thread[^]

—SA
 
Share this answer
 
Comments
Kim Togo 28-May-11 14:35pm    
Good answer, my 5.
It is a shame that it is not C# 4.0. The new Task Parallel Library is a really great tool.
Sergey Alexandrovich Kryukov 28-May-11 14:46pm    
Thank you Kim.
Task Parallel library is not quite related to the topic. Tasks are done on top of threads, did you know that?
In many cases we need threads, not tasks.
--SA
You have to change

update(DataTable dt)
{
}

To
update(object data)
{
  DataTable dt = (DataTable) data;
}


See constructor for Thread[^] and code example under ParameterizedThreadStart [^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-May-11 13:48pm    
You resolve the problem, but I can vote only 4.
Not everything is good in Microsoft! The ParameterizedThreadStart sample code you reference is pretty bad, and the hole idea of ParameterizedThreadStart is really stupid. I advice to never use it -- it is never useful.

In my solution I show how to do it right. It may look surprising, but it's easier, safer and more universal at the same time. Please see.
--SA
Kim Togo 28-May-11 14:31pm    
Thanks SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900