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...

Re: Threads how to get variables... by Steve

Steve
Tue Mar 22 05:24:17 CST 2005

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);
// ...
// ...
}
}



"aggc" <aggc@discussions.microsoft.com> wrote in message
news:C6DD1FAE-0622-4DBA-BE9F-C5B7CAFC6794@microsoft.com...
> 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...
>
>
>
>



Re: Threads how to get variables... by Richard

Richard
Tue Mar 22 05:40:45 CST 2005

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...