읽고 쓸 수있는 파일이 있습니다. 나는 그 편지가 쓰여졌을 때 아무도 그 편지에 글을 쓰려고하지 않을 것입니다.멀티 스레딩 잠금 및 모니터 클래스가 작동하지 않습니다.
읽기 또는 쓰기를 허용하는 전체 기능에 잠금을 설정했지만 여전히 오류가 발생합니다. 다른 프로세스에서 사용 중이기 때문에 'FILENAME'파일에 액세스 할 수 없습니다.
public static TYPE Property{
get{
data mydata;
Object obj = new object();
Monitor.Enter(obj);
// check if data has not changed
// if it has not, just read
using (Stream stream = File.Open(fileLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
//....
}
// else, if data changed, then need to write to file to save the new data
using (Stream stream = File.Open(fileLocation, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) {
BinaryFormatter bf = new BinaryFormatter();
try {
bf.Serialize(stream, (data);
}
//DONE processing
Monitor.Pulse(obj);
Monitor.Exit(obj);
return data
}
부동산 외부에이 장소를 두는 것을 의미합니까? – user176657
예 - 동일한 모니터를 여러 번 사용할 수 있습니다. –