/// <summary> /// Kills the given <paramref name="winTask"/>. /// </summary> /// <param name="winTask"><see cref="WinTask"/> to be killed.</param> /// <returns><see cref="Task{TResult}"/></returns> public Task Kill(WinTask winTask) { return(Task.Run(() => { var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process"; using (var searcher = new ManagementObjectSearcher(wmiQueryString)) using (var results = searcher.Get()) { var query = from p in Process.GetProcesses() join mo in results.Cast <ManagementObject>() on p.Id equals(int) (uint) mo["ProcessId"] select new { Process = p, Path = (string)mo["ExecutablePath"], CommandLine = (string)mo["CommandLine"], }; foreach (var item in query) { if (item.Path == winTask.ExecutablePath) { item.Process.Kill(); } } } })); }
/// <summary> /// Kills the given tasks and reloads all visible tasks. /// </summary> /// <param name="task">Task to be killed.</param> /// <returns><see cref="Task{TResult}"/></returns> private async Task KillTask(WinTask task) { try { await Model.Kill(task); } catch (Exception) { //Ignored. } await OnLoadAsync(); }
private void SetFunction(object sender, EventArgs e) { switch (((Button)sender).Text) { case "路径规划": WinRule _WinRule = new WinRule(); _LocalHost = ""; this.label5.Text = ""; if (_SetPoint != "") { _WinRule.MoveNodeID(_SetPoint); } _WinRule.ShowDialog(); if (_WinRule.PassStr != "") { _Ques.Enqueue(_WinRule._hts); _DevID = _WinRule.DevID; } break; case "避障设置": WinSigne _WinSigne = new WinSigne("1"); _WinSigne.ShowDialog(); if (_WinSigne.RetuStr != "") { foreach (Control Conn in this.panel1.Controls) { if (Conn is Button) { if (Conn.Text.Trim() == _WinSigne.RetuStr) { _SetPoint = _WinSigne.RetuStr; //btnA2.Location = new Point(Conn.Location.X, Conn.Location.Y); } } } } SetColor(); break; case "任务管理": WinTask _WinTask = new WinTask(); _WinTask.ShowDialog(); break; } }
/// <summary> /// Kills the given <paramref name="winTask"/>. /// </summary> /// <param name="winTask"><see cref="WinTask"/> to be killed.</param> /// <returns><see cref="Task{TResult}"/></returns> public Task Kill(WinTask winTask) { return(_winTaskService.Kill(winTask)); }