📄 consumer.cs
字号:
using System;
using System.Threading;
namespace Multithreading
{
/// <summary>
/// Summary description for Consumer.
/// </summary>
class Consumer
{
private SharedIntegerSynchronized sharedLocation;
// constructor
public Consumer(
SharedIntegerSynchronized shared)
{
sharedLocation = shared;
}
// read sharedLocation's value four times
public void Consume()
{
int sum = 0;
// get current thread
Thread current = Thread.CurrentThread;
// sleep for an interval of upto 400 milliseconds
// then add sharedLocation's Buffer property value
// to sum
for ( int count = 1; count <= 4; count++ )
{
Thread.Sleep( 400 );
sum += sharedLocation.Buffer;
}
Console.WriteLine( Thread.CurrentThread.Name +
" 读取值总计:" + sum +
".\n终止" + Thread.CurrentThread.Name + ".\n" );
} // end method Consume
} // end class Consumer
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -