我想学习一点关于.NET中的多线程并从MSDN中获取这个示例.它编译很好但在运行时崩溃.我希望微软会告诉我创建多个线程的正确方法.我无法弄清楚为什么它会崩溃.有人可以帮忙吗?
// Mutex.cs
// Mutex object example
using System;
using System.Threading;
public class MutexSample
{
static Mutex gM1;
static Mutex gM2;
const int ITERS = 100;
static AutoResetEvent Event1 = new AutoResetEvent(false);
static AutoResetEvent Event2 = new AutoResetEvent(false);
static AutoResetEvent Event3 = new AutoResetEvent(false);
static AutoResetEvent Event4 = new AutoResetEvent(false);
public static void Main(String[] args)
{
Console.WriteLine("Mutex Sample ...");
// Create Mutex initialOwned, with name of "MyMutex".
gM1 = new Mutex(true,"MyMutex");
// Create Mutex initialOwned, with no name. …Run Code Online (Sandbox Code Playgroud)