ParallelTest.cs
namespace ParallelTest
{
class ParallelTest
{
private static int Timed_Message(String arg_Message, int arg_Interval)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Source {0} - Cycle {1} for Interval {2}", arg_Message, i, arg_Interval);
Thread.Sleep(1000 * arg_Interval);
}
Console.WriteLine("{0} - Complete", arg_Message);
return 0;
}
static void Main(string[] args)
{
int RetCode = 0;
Task RedistributionTask = new Task(() => RetCode = Timed_Message("Five ", 4));
RedistributionTask.Start();
Task AltRedistributionTask = new Task(() => RetCode = Timed_Message("Three ", 2));
AltRedistributionTask.Start();
//Timed_Message("Main", 6);
// wait for input before exiting
Console.WriteLine("Press enter to finish after both [Complete] messages appear.");
Console.ReadLine();
}
}
}
输出结果
新闻热点
疑难解答