public bool Start(int interval = 1000)
        {
            #region 启动系统性能计数器统计

            bool isSucceed;
            try
            {
                isSucceed = NetFlow.Start(interval);
                NetFlow.DataMonitorEvent += DataMonitorEvent;
                IsNetFlowRun              = true;
            }
            catch
            {
                return(false);
            }

            if (!isSucceed)
            {
                return(false);
            }

            #endregion

            #region 启动Socket包统计
            if (CheckPermission.IsAdmin())
            {
                var hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        var p = new NetPacketTool(host);
                        p.NewPacket += NewPacketEvent;
                        p.Start();
                        NetPacketList.Add(p);
                    }
                    catch
                    {
                        // ignored
                    }
                }
                if (ListTool.HasElements(NetPacketList))
                {
                    IsNetPacketRun = true;
                }
            }
            #endregion

            return(true);
        }
        private void CheckRestart()
        {
            var rest = false;

            var instance = NetCardInfoTool.GetInstanceNames();

            if (ListTool.IsNullOrEmpty(NetFlow.Instances) && ListTool.HasElements(instance))
            {
                rest = true;
            }
            if (ListTool.HasElements(NetFlow.Instances) && ListTool.HasElements(instance) &&
                string.Join(@"-", NetFlow.Instances) != string.Join(@"-", instance))
            {
                rest = true;
            }

            if (rest)
            {
                //重启 系统性能计数器
                NetFlow.Restart();
                //重启 抓包监听
                var hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        if (NetPacketList.All(x => x.IP.ToString() != host.ToString()))
                        {
                            var p = new NetPacketTool(host);
                            p.NewPacket += NewPacketEvent;
                            p.Start();
                            NetPacketList.Add(p);
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
        }
        private void NewPacketEvent(NetPacketTool tool, Packet packet)
        {
            var isGather = false;

            #region 整理TCP包
            if (packet.Protocol == Protocol.Tcp && ListTool.HasElements(TcpConnection) && ListTool.HasElements(NowProcess))
            {
                lock (TcpConnection)
                {
                    // tcp 下载
                    if (TcpConnection.Any(x => x.RemoteIP.ToString() == packet.DestinationAddress.ToString() && x.RemotePort == packet.DestinationPort))
                    {
                        var tcpDownload = TcpConnection.FirstOrDefault(x => x.RemoteIP.ToString() == packet.DestinationAddress.ToString() && x.RemotePort == packet.DestinationPort);
                        var process     = NowProcess.FirstOrDefault(x => x.Id == tcpDownload.ProcessId);
                        if (process != null)
                        {
                            var info = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == process.ProcessName);
                            if (info != null)
                            {
                                isGather               = true;
                                info.DownloadBag      += packet.TotalLength;
                                info.DownloadBagCount += packet.TotalLength;
                            }
                        }
                    }
                    // tcp 上传
                    if (TcpConnection.Any(x => x.LocalIP.ToString() == packet.SourceAddress.ToString() && x.LocalPort == packet.SourcePort))
                    {
                        var tcUpload = TcpConnection.FirstOrDefault(x => x.LocalIP.ToString() == packet.SourceAddress.ToString() && x.LocalPort == packet.SourcePort);
                        var process  = NowProcess.FirstOrDefault(x => x.Id == tcUpload.ProcessId);
                        if (process != null)
                        {
                            var info = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == process.ProcessName);
                            if (info != null)
                            {
                                isGather             = true;
                                info.UploadBag      += packet.TotalLength;
                                info.UploadBagCount += packet.TotalLength;
                            }
                        }
                    }
                }
            }
            #endregion

            #region 整理UDP包
            if (packet.Protocol == Protocol.Udp && ListTool.HasElements(UdpConnection) && ListTool.HasElements(NowProcess))
            {
                lock (UdpConnection)
                {
                    // udp 下载
                    if (UdpConnection.Any(x => x.LocalPort == packet.DestinationPort) && AllIPv4Address.Contains(packet.DestinationAddress.ToString()))
                    {
                        var udpDownload = UdpConnection.FirstOrDefault(x => AllIPv4Address.Contains(x.LocalIP.ToString()) && x.LocalPort == packet.DestinationPort);
                        var process     = NowProcess.FirstOrDefault(x => x.Id == udpDownload.ProcessId);
                        if (process != null)
                        {
                            var info = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == process.ProcessName);
                            if (info != null)
                            {
                                isGather               = true;
                                info.DownloadBag      += packet.TotalLength;
                                info.DownloadBagCount += packet.TotalLength;
                                if (info.ProcessName == @"Idle")
                                {
                                }
                            }
                        }
                    }
                    // udp 上传
                    if (UdpConnection.Any(x => x.LocalPort == packet.SourcePort) && AllIPv4Address.Contains(packet.SourceAddress.ToString()))
                    {
                        //var udpIp = AllIPv4Address.FirstOrDefault(x => x == packet.SourceAddress.ToString());
                        var ucUpload = UdpConnection.FirstOrDefault(x => AllIPv4Address.Contains(x.LocalIP.ToString()) && x.LocalPort == packet.SourcePort);
                        var process  = NowProcess.FirstOrDefault(x => x.Id == ucUpload.ProcessId);
                        if (process != null)
                        {
                            var info = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == process.ProcessName);
                            if (info != null)
                            {
                                isGather             = true;
                                info.UploadBag      += packet.TotalLength;
                                info.UploadBagCount += packet.TotalLength;
                                if (info.ProcessName == @"Idle")
                                {
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (!isGather)
            {
                ++LostPacketCount;
            }
        }