Without seeing how SetInput
or GetInput
are called, I have to make some assumptions.
Are you synchronising the calls to GetInput
and SetInput
? If a request comes in and you try to map to the named region before the first request has finished creating it, you're going to have problems. You'll probably want to create a shared mutex to synchronise access to the file.
Also, depending on how your web requests are handled, the process for handling the first request may have died by the time the second request comes in, which will release the handle held by the first call to MemoryMappedFile.CreateOrOpen
, resulting in the OS releasing the file. The data will not be persisted because the file is not backed by the filesystem.
Try to create a filesystem-backed shared memory region, using CreateFromFile
and see if you still get the problem.
I question your direct use of shared memory, though. I don't know anything about your project, but there are other mechanisms to achieve IPC. Depending on your particular case, you might find a DBMS easier to work with (even a small one like sqlite).
If it's message passing you want, there are plenty of existing options that will ease your pain for that scenario too. See this question, and this one. I think you'll have luck with WCF.