コード例 #1
0
 public void updateProcessList()
 {
     for (int i = 0; i < Convert.ToInt64(m_refmap.getValue(txtString.m_txtprocessCount)); i++)
     {
         string strProcName = m_refmap.getValue(txtString.m_txtmonProcess + i.ToString());
         //get all the instances of the process
         Process[] procList = Process.GetProcessesByName(strProcName);
         foreach (Process proc in procList)
         {
             if (m_hsCpuUsageObjects.ContainsKey(proc.Id))//if the process id is available then check if the process exists
             {
                 if (!isProcessExists(proc.Id, strProcName))
                 {
                     m_hsCpuUsageObjects.Remove(proc.Id);
                     updatePerfCounterList(strProcName);
                 }
             }
             else
             {
                 m_hsCpuUsageObjects.Add(proc.Id, new CpuUsage(proc.Id));
                 updatePerfCounterList(strProcName);
             }
         }
     }
 }
コード例 #2
0
        static void sendDataToServer()
        {
            //socket connection
            m_Iphe      = Dns.GetHostEntry(m_map.getValue(txtString.m_txtserverIP));
            m_Ipep      = new IPEndPoint(m_Iphe.AddressList[0], (int)Convert.ToInt64(m_map.getValue(txtString.m_txtserverPort)));
            m_socClient = new Socket(m_Ipep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                m_socClient.Connect(m_map.getValue(txtString.m_txtserverIP), (int)Convert.ToInt64(m_map.getValue(txtString.m_txtserverPort)));
            }
            catch (SocketException exc)
            {
                m_bIsSocketConnected = false;
                Console.WriteLine("Socket connection failed : " + exc.Message);
            }

            int sendServerIter = (int)Convert.ToInt64(m_map.getValue(txtString.m_txtsendServerIter));

            sendServerIter = sendServerIter * 60;//as the value will be in minutes
            int counter = 0;

            while (true == m_bIsSocketConnected && true == m_socClient.Connected)
            {
                if (counter == sendServerIter)
                {
                    counter = 0;//reset the counter
                    try
                    {
                        m_mutSyncFile.WaitOne();
                        string strMessage = "";
                        if (true == System.IO.File.Exists(m_strStatsLogFile))
                        {
                            strMessage = System.IO.File.ReadAllText(m_strStatsLogFile);
                        }
                        m_mutSyncFile.ReleaseMutex();
                        if (strMessage.Length > 0)//make a socket connection when there is any data available
                        {
                            byte[] byData = System.Text.Encoding.ASCII.GetBytes(strMessage.ToString());
                            if (byData.Length == m_socClient.Send(byData))
                            {
                                //soon after the data has been sent to the server the data should be erased
                                m_mutSyncFile.WaitOne();
                                System.IO.File.WriteAllText(m_strStatsLogFile, "");
                                m_mutSyncFile.ReleaseMutex();
                            }
                        }
                    }
                    catch (SocketException exSoc)
                    {
                        m_bIsSocketConnected = false;
                        Console.WriteLine("Send data failed : " + exSoc.Message);
                        //at any cost delete the content of the file, else for a non existent socket the file size keeps on increasing
                        m_mutSyncFile.WaitOne();
                        System.IO.File.WriteAllText(m_strStatsLogFile, "");
                        m_mutSyncFile.ReleaseMutex();
                    }
                }
                else
                {
                    Thread.Sleep(1000);
                    counter++;
                }
            }
        }