Difference between revisions of "Multi thread sample CSharp"
From Logic Wiki
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:CSharp]] | [[Category:CSharp]] | ||
| + | [[Category:Tips]] | ||
| − | <pre class="brush:csharp | + | <pre class="brush:csharp;"> |
using System; | using System; | ||
using System.Threading; | using System.Threading; | ||
Latest revision as of 10:01, 13 July 2017
using System;
using System.Threading;
public class MyThread {
public static void Thread1() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("Thread1 {0}", i);
}
}
public static void Thread2() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("Thread2 {0}", i);
}
}
}
public class MyClass {
public static void Main() {
Console.WriteLine("Before start thread");
Thread tid1 = new Thread(new ThreadStart(MyThread.Thread1 ) );
Thread tid2 = new Thread(new ThreadStart(MyThread.Thread2 ) );
tid1.Start();
tid2.Start();
}
}