protected override int RunServerCore(string pipeName, IClientConnectionHost connectionHost, IDiagnosticListener listener, TimeSpan?keepAlive, CancellationToken cancellationToken) { // Grab the server mutex to prevent multiple servers from starting with the same // pipename and consuming excess resources. If someone else holds the mutex // exit immediately with a non-zero exit code var mutexName = GenerationServerConnection.GetServerMutexName(pipeName); bool holdsMutex; using (var serverMutex = new Mutex(initiallyOwned: true, name: mutexName, createdNew: out holdsMutex)) { if (!holdsMutex) { return(CommonGenerator.Failed); } try { return(base.RunServerCore(pipeName, connectionHost, listener, keepAlive, cancellationToken)); } finally { serverMutex.ReleaseMutex(); } } }
protected override bool?WasServerRunning(string pipeName) { string mutexName = GenerationServerConnection.GetServerMutexName(pipeName); return(GenerationServerConnection.WasServerMutexOpen(mutexName)); }