Problem in system.Threading.
hi
i wrote this code :
System.Threading.Thread _copyFile = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(this.CopyFile));
_copyFile.Start();
public void CopyFile()
{
System.IO.File.Copy(source, destination);
}
but when i compile my app the following error shown me :
No overload for 'CopyFile' matches delegate 'System.Threading.ParameterizedThreadStart'
How to solve my problem and how to use in threading in c# 2005 ?
Answers
try:
System.Threading.Thread _copyFile = new System.Threading.Thread(new System.Threading.ThreadStart(CopyFile));
you use the ThreadStart() if the public method has no parameters, otherwise if it does then use the code you were originally using
All Replies
try:
System.Threading.Thread _copyFile = new System.Threading.Thread(new System.Threading.ThreadStart(CopyFile));
you use the ThreadStart() if the public method has no parameters, otherwise if it does then use the code you were originally using
I have the same Issue but mine is parameterized:
private void button1_Click(object sender, EventArgs e){
Thread
t1 = new Thread(new ParameterizedThreadStart(this.DoWork));t1.Start(new StructArguments( iValues, "enter"));
}
private
void DoWork(StructArguments args){
....
}
I also tried using a delegate
private
delegate void delegateForDoWork(StructArguments args);private void button1_Click(object sender, EventArgs e)
{
Thread
t1 = new Thread(new ParameterizedThreadStart( new delegateForDoWork(DoWork)));t1.Start(new StructArguments( iValues, "enter"));
}
private void DoWork(StructArguments args)
{
....
}
No overload for 'DoWork' matches delegate 'System.Threading.ParameterizedThreadStart'
Hey, I had the same problem and here is how I solved it:
private void button1_Click(object sender, EventArgs e)
{
Thread
t1 = new Thread(new ParameterizedThreadStart(this.DoWork));t1.Start(new StructArguments( iValues, "enter"));
}
private
void DoWork(object data){
StructArguments args = (StructArguments)data;
}
As far as I understood. DoWork only accepts an object as an argument so you have to typecast that object to whatever you sent in the Start method.Hey, I had the same problem and here is how I solved it:
private void button1_Click( object sender, EventArgs e)
{
Thread t1 = new Thread ( new ParameterizedThreadStart ( this .DoWork));
t1.Start(new StructArguments( iValues, "enter"));
}
private void DoWork(object data )
{
StructArguments args = (StructArguments)data;
}
As far as I understood. DoWork only accepts an object as an argument so you have to typecast that object to whatever you sent in the Start method.
Nice this worked for me. My function was accepting a parameter of a specific type, changed it to an object and then just cast it back to what I wanted; seems strange to me?

