5

I need my Service to update fields in shared memory for a client application to read and display. I've found my current solution to be ineffective because of Session 0 Isolation.

I've renamed the mutexes in the Global namespace which fixes that element but it doesn't look as though the dll will be amenable to sharing between sessions despite one solution to Session 0 Isolation being:

"Explicitly choose either the Local\ or Global\ namespace for any named objects, such as events or mapped memory that the service makes available."

I don't know which part of the dll can be classified as a named object and it will take too long to keep re-installing and stepping through it to check.

I saw the code volumes for named channels and was put off. I don't want to create a file that touches the disk as I imagine is required of the memoryMappedFile solution. Can shared sections of dlls be made to work? Otherwise what is easiest?

public ref class ServerGUIBridge
{
public:
#pragma data_seg(".sdata")
    static int commonIntShouldBeGlobal = 0;
    static bool hasBeenInitializedMakeMeGlobal = false;
#pragma data_seg()
#pragma comment(linker, "/section:.sdata,rws")

I'm using .NET 2.0 so no WCF please.

casperOne
  • 73,706
  • 19
  • 184
  • 253
John
  • 6,433
  • 7
  • 47
  • 82
  • 1
    If you create the memory-mapped file with INVALID_FILE_HANDLE, then no file is created. It's just memory that gets paged out when not accessed for a while. Note that shared sections are a security hole - you cannot put ACLs on a shared section. (What happens if a client goes in and does `hasBeenInitializedMakeMeGlobal = false` or `commonIntShouldBeGlobal = rand()`?) – Raymond Chen Oct 18 '11 at 14:14
  • @Raymond "If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario, CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system." -- So where is it backed if system paging file is turned off? – John Oct 24 '11 at 03:33
  • 1
    "Backed by the system pagefile" is poor wording. It should really be "backed by the virtual memory system." If the pagefile is disabled, then the virtual memory system is just physical memory. – Raymond Chen Oct 24 '11 at 03:34

3 Answers3

1

I'd suggest named pipes: then you have proper controlled isolation between the two processes. Sharing DLLs sounds like it's fraught with danger.

Named pipes are documented on MSDN here: http://msdn.microsoft.com/en-us/library/aa365590.aspx

and a useful looking .NET 2.0 article is here: http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp

(Bear in mind that .NET 3.5 and above has a NetNamedPipeBinding class [ http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx ] that's part of WCF)

Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95
0

One often overlooked method of IPC is writing to the registry. For the two POD members I propose to share this would be the ideal solution. IPC, MSDN, and the registry

John
  • 6,433
  • 7
  • 47
  • 82
0

All .NET framework version have Remoting feature. It allows to call methods in another appdomain which can be in separate processes. See MSDN for samples and usage: http://msdn.microsoft.com/en-us/library/kwdt6w2k(v=VS.80).aspx

Novakov
  • 3,055
  • 1
  • 16
  • 32
  • I really should know about Remoting. One day. It's rather much by way of overhead as it pertains to inter-PC communication. – John Oct 18 '11 at 14:18
  • Remoting is available but considered obsolete for newer .NET versions, replaced by the much more flexible (and complex?) WCF. – Jeremy McGee Oct 18 '11 at 14:19
  • @JeremyMcGee Not any more; apparently WCF is now being discouraged or deprecated. However, I don’t think full-blown remoting of any kind is needed for the issue discussed on this page. Can’t one just create an object that inherits from MarshalByRef object, to share it between AppDomains? – Glenn Slayden Sep 21 '19 at 20:36