private void StopShell() { try { ShellActiveLock.AcquireWriterLock(15 * 1000); if (ShellActive) { ShellActive = false; ShellActiveLock.ReleaseWriterLock(); _process.Close(); NetClientService.SendShellStop(); } } catch (ApplicationException) { Console.WriteLine("DeadLock?? "); } finally { if (ShellActiveLock.IsWriterLockHeld) { ShellActiveLock.ReleaseWriterLock(); } } }
public void OnShellRequested(ShellAction shellAction, string command) { try { ShellActiveLock.AcquireReaderLock(15 * 1000); if (shellAction == ShellAction.Start && !ShellActive) { try { ShellActiveLock.UpgradeToWriterLock(15 * 1000); ShellActive = true; } catch (ApplicationException) { } finally { ShellActiveLock.ReleaseWriterLock(); } StartShell(); } else if (shellAction == ShellAction.Push && ShellActive) { PipeToProcess(command); } else if (shellAction == ShellAction.Stop && ShellActive) { ShellActiveLock.ReleaseReaderLock(); StopShell(); } } catch (ApplicationException) { } finally { // if shellAction == Stop, then we released the lock already if (ShellActiveLock.IsReaderLockHeld) { ShellActiveLock.ReleaseReaderLock(); } } }