i have the following code which is the entry point for the Memory-Map file, in other words this the very first request to the server, which writes the input string to the MM file so it can be available to other requests later:
internal string SetInput(string input)
{
try
{
MemoryMappedFile mmFile = MemoryMappedFile.CreateOrOpen("Map",2048,MemoryMappedFileAccess.ReadWrite);
using (MemoryMappedViewStream vStream = mmFile.CreateViewStream())
{
BinaryWriter bw = new BinaryWriter(vStream);
bw.Write(input);
}
Logger.AddEntry(Logger.Level.Inf, input);
}
catch (Exception e)
{
Logger.AddEntry(input, e);
return "W";
}
}
Now, i have the following code be used with other requests, so they can read what the first request sent:
private bool GetInput()
{
try
{
using (MemoryMappedFile mmFile = MemoryMappedFile.OpenExisting("Map"))
{
using (MemoryMappedViewStream stream = mmFile.CreateViewStream())
{
BinaryReader reader = new BinaryReader(stream);
string s = reader.ReadString();
try
{
// Do sth
}
catch (Exception e)
{
Logger.AddEntry(s, e);
return false;
}
}
}
}
catch (IOException e)
{
Logger.AddEntry(e);
return false;
}
return true;
}
But when this last function tries to open the MM file it gets a IOException: file not found.
What am i doing wrong, i thought MM files worked as a Shared Memory mechanism in .NET, or am i missing something in my code?