It is possible to implement micro thread by using yield.
class Program
{
static void Main(string[] args)
{
var microThread1 = MicroThread1();
var microThread2 = MicroThread2();
var microThread3 = MicroThread3();
Console.WriteLine("Begin");
microThread1.MoveNext();
microThread2.MoveNext();
microThread3.MoveNext();
microThread1.MoveNext();
microThread2.MoveNext();
microThread3.MoveNext();
Console.WriteLine("End");
Console.ReadLine();
}
static IEnumerator<object> MicroThread1()
{
Console.WriteLine("Mocro Thread 1-1");
yield return null;
Console.WriteLine("Mocro Thread 1-2");
yield return null;
Console.WriteLine("Mocro Thread 1-3");
yield return null;
}
static IEnumerator<object> MicroThread2()
{
Console.WriteLine("Mocro Thread 2-1");
yield return null;
Console.WriteLine("Mocro Thread 2-2");
yield return null;
Console.WriteLine("Mocro Thread 2-3");
yield return null;
}
static IEnumerator<object> MicroThread3()
{
Console.WriteLine("Mocro Thread 3-1");
yield return null;
Console.WriteLine("Mocro Thread 3-2");
yield return null;
Console.WriteLine("Mocro Thread 3-3");
yield return null;
}
}
No comments:
Post a Comment