Exemplo n.º 1
0
        private void Mainform_Load(object sender, EventArgs e)
        {
            _transferHelper = new TransferHelper();

            var td = new Thread(new ThreadStart(new Action(() =>
            {
                while (!this.IsDisposed)
                {
                    try
                    {
                        SystemInfo systemInfo = new SystemInfo();

                        var cpu = $"核心数:{systemInfo.ProcessorCount}个 使用率:{systemInfo.CpuLoad}%";

                        var mem = $"{StringExtention.ToFormatString(systemInfo.MemoryAvailable)}/{StringExtention.ToFormatString(systemInfo.PhysicalMemory)}";

                        var sb = new StringBuilder();

                        var hds = systemInfo.GetLogicalDrives();

                        foreach (var item in hds)
                        {
                            sb.Append($"{item.Name}盘 {StringExtention.ToFormatString(item.FreeSpace)}/{StringExtention.ToFormatString(item.Size)} \t");
                        }

                        try
                        {
                            this.Invoke(new Action(() =>
                            {
                                label8.Text  = cpu;
                                label9.Text  = mem;
                                label10.Text = sb.ToString();
                            }));
                        }
                        catch { }
                    }
                    catch (Exception ex)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }
            })));

            td.IsBackground = true;
            td.Start();

            NetMonitor();
        }
Exemplo n.º 2
0
        private void NetMonitor()
        {
            Thread td = new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    if (_choosed)
                    {
                        try
                        {
                            var speed = 0L;

                            if (_transferHelper.Speed.ContainsKey(_chooseIpPort))
                            {
                                speed = _transferHelper.Speed[_chooseIpPort];
                            }

                            var speedStr = StringExtention.ToFormatString(speed);

                            var total = 0L;

                            if (_transferHelper.Total.ContainsKey(_chooseIpPort))
                            {
                                total = _transferHelper.Total[_chooseIpPort];
                            }

                            var totalStr = StringExtention.ToFormatString(total);

                            SystemInfo systemInfo = new SystemInfo();

                            var list = systemInfo.GetProcessInfo(_chooseName);

                            StringBuilder sb = new StringBuilder();

                            sb.AppendLine($"pid:{list[0].Id}\r\n");

                            sb.AppendLine($"pName:{_chooseName}\r\n");

                            sb.AppendLine($"active:{StringExtention.ToFormatString(list[0].TotalMilliseconds)}\r\n");

                            sb.AppendLine($"mem:{StringExtention.ToFormatString(list[0].WorkingSet64)}\r\n");

                            sb.AppendLine($"path:{list[0].FileName}\r\n");

                            sb.AppendLine($"net:{speedStr}/{totalStr}");

                            try
                            {
                                this.Invoke(new Action(() =>
                                {
                                    label12.Text = sb.ToString();
                                }));
                            }
                            catch { }
                        }
                        catch (Exception ex)
                        {
                            _choosed = false;
                            MessageBox.Show("当前进程无法被监控,Error:" + ex.Message);
                        }
                    }
                    Thread.Sleep(100);
                }
            }));

            td.IsBackground = true;
            td.Start();
        }