示例#1
0
 /// <summary>
 /// Gets all running processes which have opened window
 /// </summary>
 private static void GetRunningProcesses()
 {
     foreach (Process p in Process.GetProcesses())
     {
         if (p.MainWindowTitle != string.Empty)
         {
             _processes.Add(p.Id, p.ProcessName + WinApiWrapper.GetProcDescription(p.Id));
         }
     }
 }
示例#2
0
        /// <summary>
        /// Procedure handles timer ticks
        /// </summary>
        /// <param name="state">Service parmeter</param>
        private void TimerTick(object state)
        {
            bool invokeStateChRequired = false;
            bool invokeAppChRequired   = false;
            int  newPid = WinApiWrapper.GetActWindowPID();

            // No active process detected
            if (newPid == 0)
            {
                return;
            }

            string newWTitle = WinApiWrapper.GetWindowTitle();
            string newPName  = WinApiWrapper.GetWindowProcName(newPid);
            string newPdesc  = WinApiWrapper.GetProcDescription(newPid);

            if (!_processes.ContainsKey(newPid))
            {
                _processes.Add(newPid, newPName);
            }

            CheckProcessesAlive();

            if (newPid != _actPid)
            {
                InvokeActPidChanged(new ProcessEventArgs(newPid));
                _actPid = newPid;
                invokeStateChRequired = true;
            }
            if (newPName != _actPname)
            {
                InvokeActPNameChanged(new ActPNameChangedHandlerArgs(newPName));
                _actPname             = newPName;
                invokeStateChRequired = true;
                invokeAppChRequired   = true;
            }
            if (newPdesc != _actPdesc)
            {
                InvokeActPDescChanged(new ActPDescChangedHandlerArgs(newPdesc));
                _actPdesc             = newPdesc;
                invokeStateChRequired = true;
                invokeAppChRequired   = true;
            }
            if (newWTitle != _actWinText)
            {
                InvokeActWindowTextChanged(new ActWindowTextChangedHandlerArgs(newWTitle));
                _actWinText           = newWTitle;
                invokeStateChRequired = true;
            }

            if (invokeAppChRequired)
            {
                InvokeActApplicationChanged(new ActApplicationChangedHandlerArgs(newPName, newPdesc, newPid));
            }

            //State changed event must be invoked last
            if (invokeStateChRequired)
            {
                InvokeActStateChanged(new ActStateChangedHandlerArgs(newPid, newPName, newPdesc, newWTitle));
            }
        }