using System.IO.MemoryMappedFiles;
namespace ConsoleApplication_IPC_FileMappingSend
{
class Program
{
static void Main(string[] args)
{
MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test", 1000);
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
accessor.Write(500, 42);
Console.WriteLine("Memory-mapped file created!");
Console.ReadLine();
accessor.Dispose();
mmf.Dispose();
}
}
}
Recvive:
using System.IO.MemoryMappedFiles;
namespace ConsoleApplication_IPC_FileMappingRec
{
class Program
{
static void Main(string[] args)
{
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("test");
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
int value = accessor.ReadInt32(500);
Console.WriteLine("the answer is {0}", value);
Boolean zeon1 = accessor.CanRead;
mmf.Dispose();
Console.ReadLine();
}
}
}
不錯的文章:
Working
with memory mapped files in .NET 4
.NET 4.0 New Feature - Memory Mapped File
C#
Send Data Between Processes (w/ Memory Mapped File)
Using Memory-Mapped Files
沒有留言:
張貼留言