1
我的問題是我無法打開文件。在另一個過程中或在同一個過程中!託管內存映射文件
代碼:
var path = @"c:\work\mmf.dat";
var map = "testmap123";
var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
if (fs.Length == 0)
{
fs.SetLength(1024);
}
var sec = new MemoryMappedFileSecurity();
var mem = MemoryMappedFile.CreateFromFile(fs, map, fs.Length, MemoryMappedFileAccess.ReadWrite, sec, HandleInheritability.Inheritable, false);
// Problem here System.UnauthorizedAccessException
var tmp = MemoryMappedFile.OpenExisting(map, MemoryMappedFileRights.FullControl, HandleInheritability.Inheritable);
什麼是你的錯誤代碼? –
7FF8FFFB訪問路徑被拒絕。 – nim
您在MemoryMappedFileSecurity上佔用了一個快捷方式。換一個,改爲null。 –