473,388 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Passing parameters to a thread

Hi,

I called a function of a class from a form like:
Expand|Select|Wrap|Line Numbers
  1. myController.BackupProc(myHandle);
  2.  
In the class myController, I have the following code:
Expand|Select|Wrap|Line Numbers
  1. public virtual void BackupProc(IntPtr thisHandle)
  2. {
  3.       mBackgroundThread = new Thread(new ThreadStart(DoBackup));
  4.       mBackgroundThread.Start();
  5. }
  6.  
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:

Expand|Select|Wrap|Line Numbers
  1. private void DoBackup()
  2. {
  3.    this.invoke(new BackgroundThreadCB(HandleDeviceBusy));
  4. }
  5.  
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:
Expand|Select|Wrap|Line Numbers
  1. myController.BackupProc(myHandle, this);
  2. public virtual void BackupProc(IntPtr thisHandle, Form1 thisForm)
  3. {
  4.       mBackgroundThread = new Thread(new ParameterizedThreadStart(DoBackup(thisForm)));
  5.       mBackgroundThread.Start();
  6. }
  7.  
this here gives me an error 'method required'. Kindly advise what needs to be done.
Jul 2 '08 #1
1 1067
Curtis Rutland
3,256 Expert 2GB
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
Jul 2 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: Job Lot | last post by:
How can I pass parameters to a procedure which is called in thread? '! Spin off a new thread. myThread = New Thread(New ThreadStart(AddressOf GetRawFigures)) myThread.IsBackground = True...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
2
by: Carlos | last post by:
Hi all, I am familiar with passing parameters to a thread function using C++, but I needt to learn it using C#. Can someone shed some light on how to do this? Code snippets will be great to show...
8
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.