1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| class Program { static void Main(string[] args) { Thread thread = new Thread(GO); thread.Start(); GO(); ThreadTest test = new ThreadTest(); new Thread(test.Test).Start(); Thread.Sleep(1000); test.Test(); bool done = false; ThreadStart action = () => { if (!done) { done = true; System.Console.WriteLine("Done"); } }; new Thread(action).Start(); Thread.Sleep(new TimeSpan(0, 0, 1)); action.Invoke(); ThreadTest test1 = new ThreadTest(); ThreadTest test2 = new ThreadTest(); new Thread(test1.AnotherTest).Start(); Thread.Sleep(10); test2.AnotherTest(); }
static void GO() { for (int cycle = 0; cycle< 3; cycle++) { System.Console.WriteLine("hello..."); } }
}
class ThreadTest { private bool _done; private static bool done; public void AnotherTest() { if(!done) { System.Console.WriteLine("DONE!"); done = true; } } public void Test() { if(!_done) { System.Console.WriteLine("Done!"); _done = true; } }
}
|