using MMF and C# I was creating a Shared Memory between 2 processes.
my aim is to create it as a global say 4000 byte length and create partitions
so Main proj is "MainProj" will start the MMF Named "$AppName$_sharedMMF"
then "Debugger Proj" will Access that "$AppName$_sharedMMF"
so the accessor positions are:
MainProj->Debugger : readAddr = 0 , writeAddr = 250
Debbugger->MainProj : reafAddr = 250, writeAddr = 0
then the third executable in my solution will be
//setter getter
MainProj->AnotherExe : readAddr = 251 , writeAddr = 500
//setter getter
EnotherExe->MainProj : reafAddr = 500, writeAddr = 251
the problem I am facing is now that I would like the mainProj to be a Global instance of MMF
so every time I would like to access partition I will use same static class and method
//accessed by main project
SharedSetter(SelectedGetter, Data)
1) as it is shared by multiple threads it's bit complicated as is, though adding the partition is not suppose to be complicated as the whole setup does, is this a bad idea ?
2) is it true that I can not skip the create new instance step of the mmf and leave it "Alive" and only create new accessors?
3) does any one have the approache implemented?
static void Main(string[] args)
{
FsMomitorIPCCarier data = new FsMomitorIPCCarier("someData");
IpcAccessorSetting curSrv = new IpcAccessorSetting(IPChannelS.FsMonitor, IpcAccessorThreadNameS.FsmonitorThrd, 0, 2000);
MMFDepositT FsMonitorSetterDepo = null;
try
{
FsMonitorSetterDepo = new MMFDepositT(curSrv.Channel.ToString(),curSrv.AccThreadName.ToString(), 4096);
FsMonitorSetterDepo.ReadPosition = curSrv.AccessorSectorsSets.DepoSects.Setter.Read;
FsMonitorSetterDepo.WritePosition =curSrv.AccessorSectorsSets.DepoSects.Setter.Write;
Console.WriteLine("MonitorSetterDepo.ReadPosition " + FsMonitorSetterDepo.ReadPosition);
Console.WriteLine("MonitorSetterDepo.WritePosition " + FsMonitorSetterDepo.WritePosition);
FsMonitorSetterDepo.DataReceived += new EventHandler<MemoryMappedDataReceivedEventArgs>(FsMonitorSetter_DataReceived);
FsMonitorSetterDepo.StartReader();
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("MonitorSetterDepo ctor: " + e.Message);
}
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("MonitorSetterDepo is now online");
var msg = data.DipositStrVal.StrValue.Val;
Console.WriteLine("Data = " + msg);
bool quit = false;
while (!quit)
{
Console.ReadLine();
if (!string.IsNullOrEmpty(msg))
{
var dataDelvr = data.IpcCarierToByteArray();
FsMonitorSetterDepo.Write(dataDelvr);
}
else
{
quit = true;
}
//msg = "";
}
//DepoTest.statusSet.ForEach(SttM => Console.WriteLine(SttM));
FsMonitorSetterDepo.Close();
FsMonitorSetterDepo = null;
}
来源:https://stackoverflow.com/questions/35421212/ipc-using-shared-and-as-global-mmf