public ConEmuSession Start([NotNull] ConEmuStartInfo startinfo) { if (startinfo == null) { throw new ArgumentNullException(nameof(startinfo)); } // Close prev session if there is one _running?.CloseConsoleEmulator(); if (_running != null) { throw new InvalidOperationException("Cannot start a new console process because another console emulator session has failed to close in due time."); } _autostartinfo = null; // As we're starting, no more chance for an autostart if (!IsHandleCreated) { CreateHandle(); } // Spawn session var session = new ConEmuSession(startinfo, new ConEmuSession.HostContext((void *)Handle, IsStatusbarVisible)); _running = session; StateChanged?.Invoke(this, EventArgs.Empty); startinfo.ConsoleProcessPreExitedEventSink += (sender, args) => OnSessionEnds(); // Wait for its exit session.WaitForConsoleEmulatorCloseAsync().ContinueWith(scheduler: TaskScheduler.FromCurrentSynchronizationContext(), continuationAction: task => { OnSessionEnds(); }); return(session); }
public ConEmuSession Start([NotNull] ConEmuStartInfo startinfo) { if(startinfo == null) throw new ArgumentNullException(nameof(startinfo)); // Close prev session if there is one _running?.CloseConsoleEmulator(); if(_running != null) throw new InvalidOperationException("Cannot start a new console process because another console emulator session has failed to close in due time."); _autostartinfo = null; // As we're starting, no more chance for an autostart if(!IsHandleCreated) CreateHandle(); // Spawn session var session = new ConEmuSession(startinfo, new ConEmuSession.HostContext((void*)Handle, IsStatusbarVisible)); _running = session; StateChanged?.Invoke(this, EventArgs.Empty); // Wait for its exit session.WaitForConsoleEmulatorCloseAsync().ContinueWith(scheduler : TaskScheduler.FromCurrentSynchronizationContext(), continuationAction : task => { try { _nLastExitCode = _running.GetConsoleProcessExitCode(); } catch(Exception) { // NOP } _running = null; Invalidate(); StateChanged?.Invoke(this, EventArgs.Empty); }); return session; }
public ConEmuSession Start([NotNull] ConEmuStartInfo startinfo, [NotNull] JoinableTaskFactory joinableTaskFactory, [NotNull] string conEmuStyle, string conEmuFontSize) { if (startinfo == null) { throw new ArgumentNullException(nameof(startinfo)); } SetConsoleFontSize(); SetConsoleStyle(); // Close prev session if there is one _running?.CloseConsoleEmulator(); if (_running != null) { throw new InvalidOperationException("Cannot start a new console process because another console emulator session has failed to close in due time."); } _autostartinfo = null; // As we're starting, no more chance for an autostart if (!IsHandleCreated) { CreateHandle(); } // Spawn session var session = new ConEmuSession(startinfo, new ConEmuSession.HostContext((void *)Handle, IsStatusbarVisible), joinableTaskFactory); _running = session; StateChanged?.Invoke(this, EventArgs.Empty); // Wait for its exit session.WaitForConsoleEmulatorCloseAsync().ContinueWith(scheduler: TaskScheduler.FromCurrentSynchronizationContext(), continuationAction: task => { try { _nLastExitCode = _running.GetConsoleProcessExitCode(); } catch (Exception) { // NOP } _running = null; Invalidate(); StateChanged?.Invoke(this, EventArgs.Empty); }).Forget(); return(session); void SetConsoleFontSize() { var startInfoBaseConfiguration = startinfo.BaseConfiguration; if (!string.IsNullOrWhiteSpace(conEmuFontSize)) { if (int.TryParse(conEmuFontSize, out var fontSize)) { var nodeFontSize = startInfoBaseConfiguration.SelectSingleNode("/key/key/key/value[@name='FontSize']"); if (nodeFontSize?.Attributes != null) { nodeFontSize.Attributes["data"].Value = fontSize.ToString("X8"); } } } startinfo.BaseConfiguration = startInfoBaseConfiguration; } void SetConsoleStyle() { if (conEmuStyle != "Default") { startinfo.ConsoleProcessExtraArgs = " -new_console:P:\"" + conEmuStyle + "\""; } } }