我的问题是基于继承了我不能做很多的遗留代码.基本上,我有一个会产生数据块的设备.一个将调用设备来创建该数据块的库,由于某种原因我不完全理解并且即使我想要也不能改变,将该数据块写入磁盘.
此写入不是即时的,但最多可能需要90秒.在那个时候,用户想要获得正在生成的数据的部分视图,所以我想要一个消费者线程来读取另一个库写入磁盘的数据.
在我触摸这个遗留代码之前,我想使用完全控制的代码模仿问题.我正在使用C#,表面上是因为它提供了我想要的许多功能.
在生成器类中,我有这个代码创建一个随机数据块:
FileStream theFS = new FileStream(this.ScannerRawFileName,
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
//note that I need to be able to read this elsewhere...
BinaryWriter theBinaryWriter = new BinaryWriter(theFS);
int y, x;
for (y = 0; y < imheight; y++){
ushort[] theData= new ushort[imwidth];
for(x = 0; x < imwidth;x++){
theData[x] = (ushort)(2*y+4*x);
}
byte[] theNewArray = new byte[imwidth * 2];
Buffer.BlockCopy(theImage, 0, theNewArray, 0, imwidth * 2);
theBinaryWriter.Write(theNewArray);
Thread.Sleep(mScanThreadWait); //sleep for 50 milliseconds
Progress = (float)(y-1 >= 0 ? y-1 …Run Code Online (Sandbox Code Playgroud)