public MainForm() { InitializeComponent(); // pass formMethods the created Form this formMethods = new FormMethods(this); cmdProcess.GetProcess.Start(); // Begin and cancel so the RichTextBox will stay clean. Otherwise it will start in line 2. cmdProcess.GetProcess.BeginOutputReadLine(); cmdProcess.GetProcess.CancelOutputRead(); cmdProcess.GetProcess.OutputDataReceived += AppendReceivedData; cmdProcess.GetProcess.ErrorDataReceived += AppendReceivedData; Thread.Sleep(20); cmdProcess.GetProcess.BeginOutputReadLine(); cmdProcess.GetProcess.BeginErrorReadLine(); rtb_console.Clear(); cmdProcess.CommandExecutionStarted += CommandExecutionStarted; cmdProcess.ClearConsole += () => { rtb_console.Clear(); }; // Select custom command control cbx_customCommand.Select(); // Start the watcher which fires if adb devices changed AdbDeviceWatcher.DeviceChanged += DwAdb_DeviceChanged; AdbDeviceWatcher.StartDeviceWatcher(); }
public void StartProcessing(string @command, string @serialnumber) { if (command.StartsWith("adb")) { if (AdbDeviceWatcher.GetConnectedAdbDevices() > 0 || command.EndsWith("help") || command.EndsWith("version") || command.StartsWith("adb connect") || command.StartsWith("adb disconnect")) { StopProcessing(); Thread.Sleep(50); CommandExecutionStarted?.Invoke(); process.StandardInput.WriteLine(CommandParser(command, serialnumber)); } else { MessageBoxTimeout((IntPtr)0, ERROR_MSG, ERROR_TITLE, 48, 0, 1600); //MessageBox.Show(ERROR_MSG,ERROR_TITLE , MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (command.StartsWith("cls")) { ClearConsole?.Invoke(); } else { StopProcessing(); Thread.Sleep(50); CommandExecutionStarted?.Invoke(); process.StandardInput.WriteLine(CommandParser(command, serialnumber)); } }
public void StartProcessing(string @command, string @serialnumber) { if (command.StartsWith("adb")) { if (AdbDeviceWatcher.GetConnectedAdbDevices() > 0 || command.EndsWith("help") || command.EndsWith("version") || command.StartsWith("adb connect") || command.StartsWith("adb disconnect")) { StopProcessing(); Thread.Sleep(50); CommandExecutionStarted?.Invoke(); process.StandardInput.WriteLine(CommandParser(command, serialnumber)); } else { MessageBox.Show("No device connected. Please connect a device for adb commands.", "Error - No Device Found", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (command.StartsWith("cls")) { ClearConsole?.Invoke(); } else { StopProcessing(); Thread.Sleep(50); CommandExecutionStarted?.Invoke(); process.StandardInput.WriteLine(CommandParser(command, serialnumber)); } }
public string StartProcessingInThread(string @command, string @serialnumber) { if (command.StartsWith("adb")) { if (AdbDeviceWatcher.GetConnectedAdbDevices() > 0 || command.EndsWith("help") || command.EndsWith("version") || command.StartsWith("adb connect") || command.StartsWith("adb disconnect")) { string output = ""; Thread t = new Thread(() => { output = StartProcessingReadToEnd(command, serialnumber); }) { IsBackground = true }; t.Start(); while (t.IsAlive) { Application.DoEvents(); } return(output); } else { return(null); } } else { string output = ""; Thread t = new Thread(() => { output = StartProcessingReadToEnd(command, serialnumber); }) { IsBackground = true }; t.Start(); while (t.IsAlive) { Application.DoEvents(); } return(output); } }