How to create a memory mapped file in a service?
-
Hi, I'm trying to create a memory mapped file file using
var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using
var mmf = MemoryMappedFile.OpenExisting("memMapFile");
leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!
-
Hi, I'm trying to create a memory mapped file file using
var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using
var mmf = MemoryMappedFile.OpenExisting("memMapFile");
leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!
You need to create an inter-process memory map file with
MemoryMappedFile.CreateNew
method. In this way you'll be able to access it from different processes. -
Hi, I'm trying to create a memory mapped file file using
var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using
var mmf = MemoryMappedFile.OpenExisting("memMapFile");
leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!
Is it a local variable in the method? Or a member of the class?
-
You need to create an inter-process memory map file with
MemoryMappedFile.CreateNew
method. In this way you'll be able to access it from different processes.Not if he's only accessing it from the Service, not from other processes.
-
You need to create an inter-process memory map file with
MemoryMappedFile.CreateNew
method. In this way you'll be able to access it from different processes. -
Is it a local variable in the method? Or a member of the class?