Ask a questionAsk a question
 

AnswerProblem in system.Threading.

  • Thursday, October 19, 2006 10:41 PMHamed_1983 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Thursday, October 19, 2006 10:53 PMahmedilyasMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Thursday, October 19, 2006 10:53 PMahmedilyasMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Tuesday, July 03, 2007 3:15 PMLivery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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'

     

  • Sunday, September 09, 2007 10:11 PMhriceto Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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.

  • Wednesday, November 04, 2009 10:07 AMsparky_david Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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?