public void RunLoop() { //获取当前线程的名称 string threadName = Thread.CurrentThread.Name; for (int i = 0; i < Count; i++) { Console.WriteLine("{0}计数:{1}", threadName, i.ToString()); parent.update(threadName.ToString() + "计数:" + i.ToString()); //线程休眠500毫秒 Thread.Sleep(1000); } Console.WriteLine("{0}完成计数", threadName); parent.update(threadName.ToString() + "完成计数"); }
public void Thread2() { string strMsg = "这是一个个实例方法"; Console.WriteLine(strMsg); //showComment(strMsg); parent.update(strMsg); }
public void Consumer() { while (true) { int result; mut.WaitOne(); if (SharedBuffer == 0) { Console.WriteLine("Consumed {0}: end of data\r\n", SharedBuffer); parent.update("Consumed " + SharedBuffer + " : end of data\r\n"); mut.ReleaseMutex(); break; } if (SharedBuffer > 0) { // ignore negative values result = SharedBuffer; Console.WriteLine("Consumed: {0}", result); parent.update("Consumed: " + result); mut.ReleaseMutex(); } } }