private static void RunUI() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(true); var service = new ServiceThread { ServiceFactory = () => new MouseBridgeService() }; var tray = new MouseTrapTrayIcon(service); var app = new TrayApplication(tray); app.BeforeStart += (s, e) => { if (Settings.Load().TeleportationActive) { service.StartService(); } }; app.BeforeExit += (s, e) => { service.StopService(); }; app.Start(); } catch (Exception e) { Logger.Error(e.Message, e); MessageBox.Show($"[{e.GetType().FullName}] {e.Message}\r\n{e.StackTrace}", e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
public static void ThreadStopped(Thread threadToStop) { ThreadLocalServiceRequest req = threadToStop.localServiceRequest; req.tag = ThreadLocalServiceRequestTag.ThreadStopped; req.targetThread = threadToStop; ServiceThread.Request(req); }
public static void StopProcess(Process process, int exitCode) { ThreadLocalServiceRequest req = Thread.CurrentThread.localServiceRequest; req.tag = ThreadLocalServiceRequestTag.StopProcess; req.targetProcess = process; req.exitCode = exitCode; ServiceThread.Request(req); req.requestFinished.WaitOne(); process.Join(); }
public DiagnosticForm(ServiceThread service) { Service = service; InitializeComponent(); var diagnostic = false; this.BtnStartDiagnostic.Click += delegate { if (!diagnostic) { ConsoleBox.Text = string.Empty; var config = ScreenConfigCollection.Load(); Service.StopService(); Service.StartService(new MouseBridgeDiagnosticService(config, RealtimeLog)); this.BtnStartDiagnostic.Text = "Stop Diagnostic"; diagnostic = true; } else { Service.RestoreOriginalState(); this.BtnStartDiagnostic.Text = "Start Diagnostic"; diagnostic = false; } }; this.BtnCopy.Click += delegate { var sb = new StringBuilder(); // update log infos LogfileBox.Text = string.Empty; InitLogFileInfos(); sb.AppendLine(InfosBox.Text); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(ConsoleBox.Text); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(LogfileBox.Text); Clipboard.SetText(sb.ToString()); MessageBox.Show("Diagnostic data copied to clipboard."); }; this.Closing += delegate { Service.RestoreOriginalState(); }; ConsoleBox.Text = "\r\n INFO: Start Diagnostic to see Realtime output.."; InitSystemInfos(); InitLogFileInfos(); }
public ConfigFrom(ServiceThread service) { this.Icon = App.Icon; Service = service; Screens = ScreenConfigCollection.Load(); Settings = Settings.Load(); Settings.Configured = Screens.Any(_ => _.HasBridges); InitializeComponent(); this.Text += $" v{Assembly.GetEntryAssembly()?.GetName().Version}"; this.ResizeRedraw = true; this.InfoText.Visible = Settings.Configured == false; this.BtnConfigure.Click += (s, e) => { ShowForms(); }; this.BtnDiagnostic.Click += (s, e) => { ShowDiagnosticForm(); }; this.EnableAutoStart.Checked = Settings.AutoStartEnabled; this.EnableAutoStart.CheckedChanged += delegate { if (EnableAutoStart.Checked) { Task.Run(() => new ProjectInstaller().Install()); Settings.AutoStartEnabled = true; } else { Task.Run(() => new ProjectInstaller().Uninstall()); Settings.AutoStartEnabled = false; } }; if (!Settings.Configured && !Settings.AutoStartEnabled) { this.EnableAutoStart.Checked = true; } this.TeleportationActive.Checked = Settings.TeleportationActive; this.TeleportationActive.CheckedChanged += delegate { if (TeleportationActive.Checked) { Service.StartService(); Settings.TeleportationActive = true; } else { Service.StopService(); Settings.TeleportationActive = false; } }; }
public static bool ResumeProcess(Process process, bool recursive) { ThreadLocalServiceRequest req = Thread.CurrentThread.localServiceRequest; req.tag = (recursive)? (ThreadLocalServiceRequestTag.ResumeProcessRecursive): (ThreadLocalServiceRequestTag.ResumeProcess); req.targetProcess = process; ServiceThread.Request(req); req.requestFinished.WaitOne(); return(req.processStarted); }
private void StartProcess(ServiceThread thread, Button button) { button.Text = button.Text.Replace("Start ", "Stop "); button.ForeColor = Color.Red; try { button.Enabled = false; thread.Start(); } finally { button.Enabled = true; } }
private void button3_Click(object sender, EventArgs e)//获取硬件参数 { timer1.Enabled = false; timer2.Enabled = false; try { ServiceThread.Abort(); } catch { } Usart.Delay = 20; for (int i = 1; i < 12; i++) { GetSensorHandParameter((ACFF)i); button3.Text = i.ToString() + "/" + "8"; Application.DoEvents(); } button3.Text = "获取"; Usart.Delay = 50; }
private void StopProcess(ServiceThread thread, Button button) { try { button.Enabled = false; thread.Stop(); thread = null; } finally { button.Enabled = true; button.Text = button.Text.Replace("Stop ", "Start "); button.ForeColor = Color.Green; } }
/// <summary> /// Connect to twitch service with provided username and password. /// </summary> /// <param name="channel">Channel for the bot to write messages and/or moderate.</param> /// <remarks>Passwords meaning your provided token.</remarks> /// <returns>True whether could connect otherwise false.</returns> public async Task ConnectAsync(string channel) { try { ServiceThread st = new ServiceThread(channel); st.Thread = new Thread(async() => { try { while (!st.CancellationToken.IsCancellationRequested) { if (TCPClient.Available > 0 || Reader.Peek() >= 0) { var message = await Reader.ReadLineAsync(); OnMessageReceived(new MessageReceivedEventArgs(message, channel)); } st.CancellationToken.Token.ThrowIfCancellationRequested(); } } catch (OperationCanceledException) { Debug.WriteLine($"[*] Thread ({st.Channel}) has stopped working, through a cancellation request."); } }); st.Start(); // join chatroom await SendMessageAsync( message : $"JOIN #{channel.ToLower()}", systemMessage : true ); Threads.Add(st); } catch (Exception ex) { Debug.WriteLine(ex); } }
private ServiceThread GetServiceThread() { ServiceThread result = null; switch (ServiceName) { case "TSEmailProcessor": result = new ServiceThreadPool <EmailProcessor>("EmailProcessor"); break; case "TSEmailSender": result = new ServiceThreadPool <EmailSender>("EmailSender"); break; case "TSSlaProcessor": result = new SlaProcessor(); break; case "TSSlaCalculator": result = new SlaCalculator(); break; case "TSIndexer": result = new ServiceThreadPool <Indexer>("Indexer"); break; case "TSIndexRebuilder": result = new ServiceThreadPool <Indexer>("Indexer"); break; case "TSCrmPool": result = new CrmPool(SystemUser.CRM); break; case "TSReminderProcessor": result = new ReminderProcessor(); break; case "TSImportProcessor": result = new ImportProcessor(); break; case "TSWebHooksProcessor": result = new WebHooksPool(SystemUser.CRM); break; case "TSCustomerInsights": result = new CustomerInsightsProcessor(); break; case "TSReportSender": result = new ServiceThreadPool <ReportSender>("ReportSender"); break; case "TokTranscoder": result = new ServiceThreadPool <TokTranscoder>("TokTranscoder"); break; case "TSTaskProcessor": result = new ServiceThreadPool <TaskProcessor>("TaskProcessor"); break; default: result = null; break; } return(result); }
public static void Main(string[] args) { switch (args.FirstOrDefault()) { case "-i": new ProjectInstaller().Install(); return; case "-u": MutexRunner.CloseRunningInstance(); new ProjectInstaller().Uninstall(); return; case "--reinit": ServiceThread.NotifyRestartWorker(); return; default: StartProgram(); return; } }
public MouseTrapTrayIcon(ServiceThread service) { Service = service; Icon = App.Icon; Text = App.Name; ContextMenu.Items.Add("Settings", null, (s, e) => OpenSettings()); ContextMenu.Items.Add("Reinit", null, (s, e) => Reinit()); ContextMenu.Items.Add("Exit", null, (s, e) => Close()); // make first option bold ContextMenu.Items[0].Font = WithFontStyle(ContextMenu.Items[0].Font, FontStyle.Bold); Visible = true; // show config form on first startup var settings = Settings.Load(); if (!settings.Configured) { OpenSettings(); } }
protected override void OnStart(string[] args) { //System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle; _thread = GetServiceThread(); _thread.Start(); }