Form1.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Azylee.Core.AppUtils;
  2. using Azylee.Core.DataUtils.CollectionUtils;
  3. using Azylee.Core.ProcessUtils;
  4. using Azylee.Core.WindowsUtils.CMDUtils;
  5. using Azylee.Core.WindowsUtils.InfoUtils;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Test.CmdTool
  17. {
  18. public partial class Form1 : Form
  19. {
  20. private PerformanceCounter ComCpu = ComputerStatusTool.Processor();//电脑CPU监控
  21. private PerformanceCounter AppCpu = AppInfoTool.Processor();//程序CPU监控
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Form1_Load(object sender, EventArgs e)
  27. {
  28. }
  29. private void BTFindPort_Click(object sender, EventArgs e)
  30. {
  31. if (!string.IsNullOrWhiteSpace(TBPort.Text))
  32. {
  33. var list = CMDNetstatTool.FindByPort(int.Parse(TBPort.Text));
  34. if (ListTool.HasElements(list))
  35. {
  36. list.ForEach(x =>
  37. {
  38. string name = "-";
  39. string file = "-";
  40. try
  41. {
  42. Process p = Process.GetProcessById(x.Item2);
  43. name = p?.ProcessName;
  44. file = p?.MainModule.FileName;
  45. }
  46. catch { }
  47. TBRs.AppendText($"{x.Item1}, {x.Item2}, {name}, {file}");
  48. TBRs.AppendText(Environment.NewLine);
  49. });
  50. }
  51. }
  52. }
  53. private void BTStart_Click(object sender, EventArgs e)
  54. {
  55. Task.Factory.StartNew(() =>
  56. {
  57. //CMDProcessTool.StartExecute(@"java -jar D:\CoCo\Work\supplyPlatform\out\artifacts\noah_cloud_supply_platform_jar\noah-cloud-supply-platform.jar");
  58. });
  59. }
  60. private void BTKillApp_Click(object sender, EventArgs e)
  61. {
  62. var list = CMDNetstatTool.FindByPort(int.Parse(TBPort.Text), false);
  63. if (ListTool.HasElements(list) && list.Count == 1)
  64. {
  65. try
  66. {
  67. Process p = Process.GetProcessById(list.First().Item2);
  68. p.Kill();
  69. }
  70. catch { }
  71. }
  72. }
  73. private void TMStatus_Tick(object sender, EventArgs e)
  74. {
  75. LBStatus.Text = $"comcpu:{(int)ComCpu.NextValue()}, appcpu:{(int)AppCpu.NextValue()}, appram:{AppInfoTool.RAM() / 1024}";
  76. }
  77. }
  78. }