Form1.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Execute(@"java -jar " + TBJar.Text,
  58. new Action<string>((s) =>
  59. {
  60. UIRs(s);
  61. }));
  62. });
  63. }
  64. private void BTKillApp_Click(object sender, EventArgs e)
  65. {
  66. var list = CMDNetstatTool.FindByPort(int.Parse(TBPort.Text), false);
  67. if (ListTool.HasElements(list) && list.Count == 1)
  68. {
  69. try
  70. {
  71. Process p = Process.GetProcessById(list.First().Item2);
  72. p.Kill();
  73. }
  74. catch { }
  75. }
  76. }
  77. private void TMStatus_Tick(object sender, EventArgs e)
  78. {
  79. LBStatus.Text = $"comcpu:{(int)ComCpu.NextValue()}, appcpu:{(int)AppCpu.NextValue()}, appram:{AppInfoTool.RAM() / 1024}";
  80. }
  81. private void UIRs(string s)
  82. {
  83. try
  84. {
  85. Invoke(new Action(() =>
  86. {
  87. TBRs.AppendText(s);
  88. }));
  89. }
  90. catch { }
  91. }
  92. }
  93. }