English 中文(简体)
2. 手册重新印发
原标题:Manual Reset Event Basic Question
  • 时间:2011-01-28 11:13:52
  •  标签:
  • c#

i 几乎没有混淆人工重整活动,等待一种方法,在下文中加以考虑。

static  object objLock = new object();

    static int counter = 5;

    static ManualResetEvent mEvent = new ManualResetEvent(false);

    static void Main(string[] args)
    {
        ///LeftShifting(10, 4);

       // RightShifting(3, 1);

       // Xoring(0001, 1001);

       // ExcahnageValuesWithXoring(10, 20);

       // ReverseBits(0);

        Thread.CurrentThread.Name = "Main Thread";

        for(int i=0;i<5;i++)
        {
            Thread t = new Thread(new ThreadStart(DoSomeLongWork));
            t.Name = i.ToString();
            t.Start();
        }

        Console.WriteLine("Current thread is " + Thread.CurrentThread.Name);

        mEvent.WaitOne();

        Console.WriteLine("Current thread is " + Thread.CurrentThread.Name);
        Console.WriteLine("Completed Long Running Process...");
        Console.ReadLine();
    }

    private static void DoSomeLongWork()
    {

        Console.WriteLine("Starting Long Running Process...On " + Thread.CurrentThread.Name);

        Thread.Sleep(5000);

        Interlocked.Decrement(ref counter);

        Console.WriteLine("Ending Long Running Process...On " + Thread.CurrentThread.Name);

        if (counter == 0)
            mEvent.Set();

    }

我的问题是,我所说的话。 Waitone() 就是要阻止主食或执行儿童read。

最佳回答

它是主线。 这只是can。 你们可以强迫别人睡觉。 主要read子将等到另一read子“开始”活动。 这与<代码>Monitor非常相似。 Wait/Pulse

问题回答

<代码>mEvent.Wait One()>将阻挡主线,直至儿童校对之一打电话m Event.Set(





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签