How do i give a thread a value??

  • Thread starter Thread starter GERM
  • Start date Start date
G

GERM

Hi,
Is it in dotNet possible to give a starting Thread a value on
startup??


Thread* connecttoserver = new Thread(new ThreadStart(0,
ConnectToServer));
connecttoserver->Start();
...

static void ConnectToServer(){}


^^that works fine,
but when i try to give a value to ConnectToServer it come an error

[code:1:762980b63d]
int i = 0;
Thread* connecttoserver = new Thread(new ThreadStart(0,
ConnectToServer(i)));
connecttoserver->Start();
...

static void ConnectToServer(int access){}
[/code:1:762980b63d]

thx for help

PS: i know, i can no english :P
 
Yes for some reason this works differently than in old-school C++ :P
You have to make the variable you pass a static member of the class instead,
then it'll work.
Like

static int i;

In function
i=0;

In the thread function i has the value 0.
 
Back
Top