1

I have following code:

Thread userThread = new Thread(() => UserPasswordSpawn.InputBox(ref userName, ref password));
//UserPassWordSpawn.InputBox(ref userName, ref password);
/* do some calculations while user puts in data */

userThread.Join();

The thread does not work, and never enters the InputBox() function (I set a breakpoint there, and it is never reached), while it works just fine if I do the commented part (but the calculations which should happen while the system is waiting for the user to input the data). How can I spawn a thread with 2 input parameters properly (twice ref string).

Note, the error I get is something about Thread.JoinInternal(), but the main thing is probably that the function is not called.

The call with the () => ThreadStart() I got from How to pass parameters to ThreadStart method in Thread?

Community
  • 1
  • 1
SinisterMJ
  • 3,425
  • 2
  • 33
  • 53

2 Answers2

3

By this:

Thread userThread = new Thread(() => UserPasswordSpawn.InputBox(ref userName, ref password));

you've created new thread instance.
Now you should start it by in a way like that:

userThread.Start();
alex.b
  • 4,547
  • 1
  • 31
  • 52
3

Call userThread.Start(); after creating the thread, and before joining it.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900