/// <summary> /// Terminate the control channel. /// </summary> public void TerminateControlChannel() { // Terminate the channel to avoid deadlocks if the buffer is full, and there is no active reader thread. // ControlChannel.SyncObject.TerminateChannel.Store(true); controlChannelNamedEvent.Signal(); }
/// <summary> /// Initializes a new instance of the <see cref="InterProcessMlosContext"/> class. /// </summary> /// <returns>InterProcessMlosContext instance.</returns> public static InterProcessMlosContext CreateOrOpen() { NamedEvent targetProcessNamedEvent = NamedEvent.CreateOrOpen(TargetProcessEventName); { bool shouldWaitForTargetProcess = false; try { // Try open a global shared memory and check if the tager process is fully initialized. // using SharedMemoryRegionView <MlosProxyInternal.GlobalMemoryRegion> targetProcessMemoryRegionView = SharedMemoryRegionView.OpenExisting <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize); if (targetProcessMemoryRegionView.MemoryRegion().GlobalMemoryRegionIndex == 1) { shouldWaitForTargetProcess = true; } } catch (FileNotFoundException) { // If the target process is not running. // shouldWaitForTargetProcess = true; } if (shouldWaitForTargetProcess) { // If the target process is not fully initialized, wait for the signal. // targetProcessNamedEvent.Wait(); targetProcessNamedEvent.Signal(); } } SharedMemoryRegionView <MlosProxyInternal.GlobalMemoryRegion> globalMemoryRegionView = SharedMemoryRegionView.OpenExisting <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize); SharedMemoryMapView controlChannelMemoryMapView = SharedMemoryMapView.OpenExisting(ControlChannelMemoryMapName, SharedMemorySize); SharedMemoryMapView feedbackChannelMemoryMapView = SharedMemoryMapView.OpenExisting(FeedbackChannelMemoryMapName, SharedMemorySize); // Create channel synchronization primitives. // NamedEvent controlChannelNamedEvent = NamedEvent.CreateOrOpen(ControlChannelEventName); NamedEvent feedbackChannelNamedEvent = NamedEvent.CreateOrOpen(FeedbackChannelEventName); return(new InterProcessMlosContext( globalMemoryRegionView, controlChannelMemoryMapView, feedbackChannelMemoryMapView, controlChannelNamedEvent, feedbackChannelNamedEvent, targetProcessNamedEvent)); }
/// <summary> /// Terminates the feedback channel. /// </summary> public void TerminateFeedbackChannel() { FeedbackChannel.SyncObject.TerminateChannel.Store(true); feedbackChannelNamedEvent.Signal(); }