Threads how to get variables...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

How i pass variables into threads?

For example:

Dim t1 As New Thread(AddressOf CfgInject)
Dim t2 As New Thread(AddressOf CfgInject)
t1.start
t2.start

Cfginject, can be called n times, i need to now inside the function what is
the current thread...
 
use a class, make an instance of a class, pass the values to the new class.

I do not use VB.NET so i cannot give you a VB Example (well i could, but i
am sure you can follow the this c#)

example

public class SomeClass
{
public void SomeMethod()
{
ThreadExample threadExample = new ThreadExample();
threadExample.something = "somevalue";
Thread thread = new Thread(new ThreadStart(threadExample.DoSomthing()));
thread.Start();
}
}

public class ThreadExample
{
public string something;
public void DoSomthing()
{
System.Diagnostics.Trace.WriteLine(something);
// ...
// ...
}
}
 
Do you mean how do I get hold of the current thread?

Thread.CurrentThread

Do you mean how do I pass parameters into a thread?

http://www.yoda.arachsys.com/csharp/threads/parameters.shtml

Also in version 2.0 there is a new thread constructor which takes a ParameterizedThreadStart delegate instance

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi!

How i pass variables into threads?

For example:

Dim t1 As New Thread(AddressOf CfgInject)
Dim t2 As New Thread(AddressOf CfgInject)
t1.start
t2.start

Cfginject, can be called n times, i need to now inside the function what is
the current thread...
 
Back
Top