Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Give data to a thread? 1

Status
Not open for further replies.

flnhst

Programmer
Aug 9, 2005
12
NL
How do i pass a variable to (not yet) running thread? And how do i access the variable inside the thread?
 
i think it is something like this:

Code:
public class MyThread {
	private int _data;

	public MyThreadClass(int data) {
		this._data = data;
	}

	public void Start() {
		new Thread(new ThreadStart(ThreadProc)).Start();
	}
	
	private void ThreadProc() {
		// use this._data in your thread;
	}
}

to call it, use:
Code:
new MyThread(55).Start();

but i didn't test it, don't know if it will compile, but you should get the jist of it
 
The name of the constructor was wrong, but it works perfect! Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top