AutoResetEvent.Set() 这个方法的问题,请专业人士回答

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:43:33
他是把事件状态设置为终止状态,什么意思?是哪个事件状态设置为终止状态。

具体代码
using System;
using System.Threading;

namespace AutoResetEvent_Examples
{
class MyMainClass
{
//Initially not signaled.
const int numIterations = 100;
static AutoResetEvent myResetEvent = new AutoResetEvent(false);
static int number;

static void Main()
{
//Create and start the reader thread.
Thread myReaderThread = new Thread(new ThreadStart(MyReadThreadProc));
myReaderThread.Name = "ReaderThread";
myReaderThread.Start();

for (int i = 1; i <= numIterations; i++)
{
Console.WriteLine("Writer thread writing value: {0}", i);
number = i;

//Signal that a value has been written.
myResetEvent.Set();<

事件是static AutoResetEvent myResetEvent = new AutoResetEvent(false); 这一行定义的。

AutoResetEvent 自动回调的事件吧,每当满足某种条件就自动在另个线程执行一段代码,“状态设置为终止状态”就是说当已经满足特定条件的情况下,myResetEvent 这个事件也不自动执行。