public bool Run(StartupEventArgs args) { m_mutex = new Mutex(true, m_uniqueIdentifier); if (m_mutex.WaitOne(10)) { SingleInstanceCommunicationService singleInstanceCommunicationService = new SingleInstanceCommunicationService(); m_serviceHost = new ServiceHost(singleInstanceCommunicationService, new Uri($"net.pipe://localhost/{m_uniqueIdentifier}")); m_serviceHost.AddServiceEndpoint(typeof(IRunOnceService), new NetNamedPipeBinding(), "singleInstService"); m_serviceHost.Open(); singleInstanceCommunicationService.SecondInstanceRunCalled += (sender, arg) => OnSecondInstanceStarted(new SecondInstanceEventArgs(args.Args)); return(true); } using (ChannelFactory <IRunOnceService> pipeFactory = new ChannelFactory <IRunOnceService>(new NetNamedPipeBinding(), new EndpointAddress($"net.pipe://localhost/{m_uniqueIdentifier}/singleInstService")) ) { IRunOnceService runOnceService = pipeFactory.CreateChannel(); runOnceService.SecondInstanceRun(args.Args); return(false); } }
public RunOnceServiceTest() { m_mockCache = new Mock <ICache>(MockBehavior.Strict); m_mockValidationState = new Mock <IValidationState>(MockBehavior.Strict); m_service = new RunOnceService(m_mockCache.Object, g_period, m_mockValidationState.Object); }