Just move Main
out of ThreadTest
and it should work fine. You also need to make the class and method public
(or internal
at that point):
static void Main()
{
ThreadTest tt = new ThreadTest(); // Create a common instance
new Thread (tt.Go).Start();
tt.Go();
}
public class ThreadTest
{
bool done;
// Note that Go is now an instance method
public void Go()
{
if (!done) { done = true; Console.WriteLine ("Done"); }
}
}
The "C# Program" is implicitly contained inside a class - moving main
inside a nested class is probably confusing the executor which is looking for Main
in the outermost class.