Passing parameters to a thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goilaswati
    New Member
    • Jul 2008
    • 1

    Passing parameters to a thread

    Hi,

    I called a function of a class from a form like:
    Code:
    myController.BackupProc(myHandle);
    In the class myController, I have the following code:
    Code:
    public virtual void BackupProc(IntPtr thisHandle)
    {
          mBackgroundThread = new Thread(new ThreadStart(DoBackup));
          mBackgroundThread.Start();
    }
    i.e. I am trying to start a thread from this function backupproc that I called from the form.

    In DoBackup(), I have to do the following:

    Code:
    private void DoBackup()
    {
       this.invoke(new BackgroundThreadCB(HandleDeviceBusy));
    }
    This I can do if I do not call a seperate class, but keep the code on the same form which makes it too busy.

    I want a way so that I can pass the 'this' instance of the form from the form to the class and through the thread.

    The problem comes here when I want to pass the instance of the form through the thread.
    I am trying to do something like:
    Code:
    myController.BackupProc(myHandle, this);
    public virtual void BackupProc(IntPtr thisHandle, Form1 thisForm)
    {
          mBackgroundThread = new Thread(new ParameterizedThreadStart(DoBackup(thisForm)));
          mBackgroundThread.Start();
    }
    this here gives me an error 'method required'. Kindly advise what needs to be done.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Welcome to Bytes!

    We appreciate it if you wrap your code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. And if it's easier for us to read, it's easier for us to help.

    You can type them in or use the # button on the text editor.

    MODERATOR

    Comment

    Working...