public void Start(params string[] args) { if (!BinaryFile.Exists) { throw new FileNotFoundException("The binary file does not exist.", BinaryFile.FullName); } Log.Clear(); Process = new Process { StartInfo = new ProcessStartInfo { FileName = BinaryFile.FullName, Arguments = string.Join(' ', args), RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = HideWindow, WorkingDirectory = BinaryFile.Directory.FullName } }; Process.OutputDataReceived += (s, e) => Log.TryAdd(DateTime.Now, e?.Data); Process.ErrorDataReceived += (s, e) => Log.TryAdd(DateTime.Now, e?.Data); Process.Exited += (s, e) => { Exited?.Invoke(this, Process.ExitCode); IsRunning = false; }; Process.Start(); Process.BeginOutputReadLine(); Process.BeginErrorReadLine(); IsRunning = true; }
protected virtual void OnExited(EventArgs e) { Trace.TraceInformation("App exited: '{0} {1}', ExitCode={2}, ExitTime='{3}'", FileName, CmdLine, ExitCode, ExitTime); Exited?.Invoke(this, e); }
/// <summary> /// Exits this Screen. /// </summary> /// <param name="source">Provides an exit source (used when skipping no-longer-valid modes upwards in stack).</param> protected void ExitFrom(Screen source) { if (hasExited) { return; } if (OnExiting(ParentScreen)) { return; } hasExited = true; if (ValidForResume || source == this) { Content.Expire(); } //propagate down the LifetimeEnd from the exit source. LifetimeEnd = source.Content.LifetimeEnd; Exited?.Invoke(ParentScreen); ParentScreen?.startResume(source); ParentScreen = null; Exited = null; ModePushed = null; }
public void Logout() { CurrentUser = null; IsAutorized = false; IsAdmin = false; Exited?.Invoke(); }
private void process_Exited(object sender, EventArgs e) { if (Exited != null) { Exited.Invoke(this, e); } }
public BasicGameWindow(int width, int height) : base(width, height, GraphicsMode.Default, "window", GameWindowFlags.Default, DisplayDevice.Default, 3, 2, ContextFlags) { Closing += (sender, e) => e.Cancel = ExitRequested?.Invoke() ?? false; Closed += (sender, e) => Exited?.Invoke(); Cursor = MouseCursor.Empty; MakeCurrent(); string version = GL.GetString(StringName.Version); string versionNumberSubstring = GetVersionNumberSubstring(version); GLVersion = new Version(versionNumberSubstring); version = GL.GetString(StringName.ShadingLanguageVersion); if (!string.IsNullOrEmpty(version)) { try { GLSLVersion = new Version(versionNumberSubstring); } catch (Exception e) { Logger.Error(e, $@"couldn't set GLSL version using string '{version}'"); } } if (GLSLVersion == null) { GLSLVersion = new Version(); } //Set up OpenGL related characteristics GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.StencilTest); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.ScissorTest); string extensions = ""; int numExtensions = GL.GetInteger(GetPName.NumExtensions); for (int i = 0; i < numExtensions;) { extensions += GL.GetString(StringNameIndexed.Extensions, i); if (++i < numExtensions) { extensions += " "; } } Logger.Log($@"GL Initialized GL Version: {GL.GetString(StringName.Version)} GL Renderer: {GL.GetString(StringName.Renderer)} GL Shader Language version: {GL.GetString(StringName.ShadingLanguageVersion)} GL Vendor: {GL.GetString(StringName.Vendor)} GL Extensions: {extensions}", LoggingTarget.Runtime, LogLevel.Important); Context.MakeCurrent(null); }
protected void ExitState() { Debug.LogFormat("Exit state: [{0}]", StateID); Flags.Clear(); OnExit(); Exited?.Invoke(StateID); }
private Win32Process(NativeMethods.PROCESS_INFORMATION pi, StreamWriter stdin, StreamReader stdout, StreamReader stderror) { StandardInput = stdin; StandardOutput = stdout; StandardError = stderror; _hasExited = false; _exitCodeLock = new object(); Id = pi.dwProcessId; MainThreadId = pi.dwThreadId; _processHandle = new SafeProcessHandle(pi.hProcess, true); var threadHandle = new SafeThreadHandle(pi.hThread); var wait = new ProcessWaitHandle(_processHandle); _registeredWait = ThreadPool.RegisterWaitForSingleObject(wait, (o, t) => { _registeredWait.Unregister(wait); SetExitState(); Exited?.Invoke(this, EventArgs.Empty); _processHandle.Close(); threadHandle.Close(); wait.Close(); }, null, -1, true); _disposable .Add(() => _registeredWait.Unregister(wait)) .Add(_processHandle) .Add(threadHandle) .Add(wait); }
public override void Exit() { _targetController.TargetClicked -= OnTargetClicked; _input.PressedCancel -= OnPressedCancel; Exited?.Invoke(); }
public EsoClient(string steamAppID, FolderBrowserDialog folderBrowser) { ProcessName = "eso64"; _steamAppID = (steamAppID ?? string.Empty).Replace("steam://rungameid/", ""); _folderBrowser = folderBrowser; _tick = new Timer { Interval = 1000, Enabled = true }; _tick.Tick += (s, e) => { if (Exists && !IsRunning) { IsRunning = true; Started?.Invoke(this, e); } else if (!Exists && IsRunning) { IsRunning = false; Exited?.Invoke(this, e); } }; }
/// <summary> /// Start the psuedoconsole and run the process as shown in /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole /// </summary> /// <param name="command">the command to run, e.g. cmd.exe</param> /// <param name="consoleHeight">The height (in characters) to start the pseudoconsole with. Defaults to 80.</param> /// <param name="consoleWidth">The width (in characters) to start the pseudoconsole with. Defaults to 30.</param> public void Start(string command, string directory, int consoleWidth = 80, int consoleHeight = 30) { _inputPipe = new PseudoConsolePipe(); _outputPipe = new PseudoConsolePipe(); _pseudoConsole = PseudoConsole.Create(_inputPipe.ReadSide, _outputPipe.WriteSide, consoleWidth, consoleHeight); using (var process = ProcessFactory.Start(command, directory, PseudoConsole.PseudoConsoleThreadAttribute, _pseudoConsole.Handle)) { // copy all pseudoconsole output to a FileStream and expose it to the rest of the app ConsoleOutStream = new FileStream(_outputPipe.ReadSide, FileAccess.Read); OutputReady.Invoke(this, EventArgs.Empty); // Store input pipe handle, and a writer for later reuse _consoleInputPipeWriteHandle = _inputPipe.WriteSide; _consoleInputWriter = new StreamWriter(new FileStream(_consoleInputPipeWriteHandle, FileAccess.Write)) { AutoFlush = true }; // free resources in case the console is ungracefully closed (e.g. by the 'x' in the window titlebar) OnClose(() => DisposeResources(process, _pseudoConsole, _outputPipe, _inputPipe, _consoleInputWriter)); WaitForExit(process).WaitOne(Timeout.Infinite); } Exited?.Invoke(this, EventArgs.Empty); }
public async Task <bool> LaunchGameAsync(LaunchProfile profile, Version version) { var startInfo = new ProcessStartInfo { FileName = profile.IsDebugMode ? _gamePathService.JavaPath : _gamePathService.JavawPath, WorkingDirectory = _gamePathService.WorkingDir, Arguments = BuildArguments(profile, version), UseShellExecute = profile.IsDebugMode, RedirectStandardOutput = !profile.IsDebugMode, RedirectStandardError = !profile.IsDebugMode, }; _gameProcess = Process.Start(startInfo); _gameProcess.EnableRaisingEvents = true; _gameProcess.Exited += (s, e) => Exited?.Invoke(_gameProcess.ExitCode); if (!profile.IsDebugMode) { _gameProcess.ErrorDataReceived += (s, e) => ErrorReceived?.Invoke(e.Data); _gameProcess.BeginErrorReadLine(); _gameProcess.OutputDataReceived += (s, e) => LogReceived?.Invoke(e.Data); _gameProcess.BeginOutputReadLine(); if (!_gameProcess.HasExited) { await Task.Run(() => _gameProcess.WaitForInputIdle()); } } return(!_gameProcess.HasExited); }
/// <summary> /// Exits this GameMode. /// </summary> public void Exit() { if (hasExited) { return; } if (OnExiting(ParentGameMode)) { return; } hasExited = true; Content.Expire(); LifetimeEnd = Content.LifetimeEnd; ParentGameMode?.startResume(this); Exited?.Invoke(ParentGameMode); if (ParentGameMode?.ValidForResume == false) { ParentGameMode.Exit(); } ParentGameMode = null; Exited = null; ModePushed = null; }
private void FrpProcess_Exited(object sender, EventArgs e) { IsRunning = false; frpProcess.Dispose(); frpProcess = null; Exited?.Invoke(sender, e); }
private void OnExited() { if (_signal) { Exited?.Invoke(); } }
private void Client_Exited(object sender, EventArgs e) { if (Exited != null) { Exited.Invoke(sender, e); } }
private void onMouseMove(object sender, MouseMoveEventArgs e) { if (inputEngine.Mouse.CurrentWindow == Window && e.X >= GlobalX + _hitBox.X && e.X <= GlobalX + _hitBox.X + _hitBox.Width && e.Y >= GlobalY + _hitBox.Y && e.Y <= GlobalY + _hitBox.Y + _hitBox.Height) { if (_state == InteractableState.Normal) { _state = InteractableState.Hover; Entered?.Invoke(this, EventArgs.Empty); } } else { if (_state == InteractableState.Hover) { _state = InteractableState.Normal; Exited?.Invoke(this, EventArgs.Empty); } } if (_state == InteractableState.Down) { tickX = MathUtil.Clamp(GlobalX, GlobalX + barBitmap.Width, inputEngine.Mouse.X) - GlobalX - tickBitmap.Width / 2.0d; needsUpdate = true; ValueChanged?.Invoke(this, EventArgs.Empty); } }
private void Process_Exited(object sender, EventArgs e) { output.writeInfo("LabVIEW process exited. Checking for process switch"); Process newProcess = findLabVIEWProcessByPath(lvProcess.StartInfo.FileName); if (newProcess != null) //found a process. { output.writeInfo("LabVIEW still found with PID " + newProcess.Id.ToString()); lvProcess = newProcess; processSwitched = true; } else { output.writeInfo("LabVIEW/App exiting..."); //check exit code if we havent switched processes. (If we have then this is unsupported.) if (!processSwitched) { //notify if it looks like it wasn't a clean exit. if (lvProcess.ExitCode != 0) { output.writeError("LabVIEW exited with code " + lvProcess.ExitCode.ToString()); } else { output.writeInfo("LabVIEW exited with code " + lvProcess.ExitCode.ToString()); } } lvExited.Set(); Exited?.Invoke(sender, e); } }
/// <summary> /// Creates a <see cref="GameWindow"/> with a given <see cref="IGameWindow"/> implementation. /// </summary> protected GameWindow([NotNull] IGameWindow implementation) { Implementation = implementation; Implementation.KeyDown += OnKeyDown; Closing += (sender, e) => e.Cancel = ExitRequested?.Invoke() ?? false; Closed += (sender, e) => Exited?.Invoke(); MouseEnter += (sender, args) => CursorInWindow = true; MouseLeave += (sender, args) => CursorInWindow = false; FocusedChanged += (o, e) => isActive.Value = Focused; bool firstUpdate = true; UpdateFrame += (o, e) => { if (firstUpdate) { isActive.Value = Focused; firstUpdate = false; } }; WindowStateChanged += (o, e) => isActive.Value = WindowState != WindowState.Minimized; MakeCurrent(); string version = GL.GetString(StringName.Version); string versionNumberSubstring = getVersionNumberSubstring(version); GLVersion = new Version(versionNumberSubstring); version = GL.GetString(StringName.ShadingLanguageVersion); if (!string.IsNullOrEmpty(version)) { try { GLSLVersion = new Version(versionNumberSubstring); } catch (Exception e) { Logger.Error(e, $@"couldn't set GLSL version using string '{version}'"); } } if (GLSLVersion == null) { GLSLVersion = new Version(); } Logger.Log($@"GL Initialized GL Version: {GL.GetString(StringName.Version)} GL Renderer: {GL.GetString(StringName.Renderer)} GL Shader Language version: {GL.GetString(StringName.ShadingLanguageVersion)} GL Vendor: {GL.GetString(StringName.Vendor)} GL Extensions: {GL.GetString(StringName.Extensions)}"); Context.MakeCurrent(null); }
private void CmdProcess_Exited(object sender, EventArgs e) { Exited?.Invoke(sender, new ProcessExitAgs() { Command = m_command }); m_command = String.Empty; }
private void OnExited(object sender, EventArgs e) { if (!HasExited) { HasExited = true; Exited?.Invoke(this, EventArgs.Empty); } }
private void Process_Exited(object?sender, EventArgs e) { logger.LogInformation("Clash exited."); Stop(); Exited?.Invoke(); }
private void ProcessOnExited(object sender, EventArgs e) { Exited?.Invoke(this, new ProcessExitedEventArgs(_process.ExitCode)); _process.Kill(); _process.Dispose(); _process = null; }
private void BtnMainMenu_LeftClick(object sender, EventArgs e) { Visible = false; Enabled = false; SendMessage("QUIT"); socket.Close(); Exited?.Invoke(this, EventArgs.Empty); }
private void OnDisconnected(object sender, EventArgs e) { if (_stream != null) { _stream.Dispose(); } Exited?.Invoke(this, null); }
private void ReceiveExit(object sender, EventArgs e) { Task.WhenAll(_stdoutTask !.Task, _stderrTask !.Task).ContinueWith(task => { Exited?.Invoke(sender, GetResult()); return(_mainTask.TrySetResult(true)); }); }
private void OnExited(object sender, EventArgs e) { _gameProcess.Exited -= OnExited; _gameProcess.OutputDataReceived -= OnOutputDataReceived; _gameProcess.ErrorDataReceived -= OnErrorDaraReceived; _logService.Info(nameof(LaunchService), $"Game exited with {_gameProcess.ExitCode}"); Exited?.Invoke(_gameProcess.ExitCode); }
protected override void BtnLeaveGame_LeftClick(object sender, EventArgs e) { this.Enabled = false; this.Visible = false; Exited?.Invoke(this, EventArgs.Empty); topBar.RemovePrimarySwitchable(this); }
private bool p_KillProcess() { if (_process == null) { return(true); } if (state == State.Killing) { return(false); } //Update the state bool isExiting = state == State.Exiting; state = State.Killing; try { //Kill the process if we are exiting if (!_process.HasExited && !isExiting) { Log("Killing Process"); try { _process.StandardOutput.Close(); _process.Kill(); } catch (System.ComponentModel.Win32Exception ex) { LogError(ex, "Failed to kill: {0}"); } //Read to end then wait for exit Log("Reading until end..."); Log("Waiting for exit"); _process?.WaitForExit(); } } catch (System.InvalidOperationException e) { LogError(e, "IOE: {0}"); } //Dispose of the process Log("Disposing and cleaning up process"); _process?.Dispose(); _process = null; Log("Killing finished"); state = State.Offline; Log("Invoking On Exit"); Exited?.Invoke(); return(true); }
public void Exit(int exitCode) { if (!HasExited) { IsRunningService = false; ExitCode = exitCode; HasExited = true; Exited?.Invoke(); } }