Exemple #1
0
        /// <summary>
        /// Process opening code. Generates a list of modules too.
        /// </summary>
        public void OpenTheProc()
        {
            ProcTypeBox.Invoke((MethodInvoker) delegate
            {
                if (String.Compare(ProcTypeBox.Text, "Name") == 0) // if combobox set to Name, use string
                {
                    ProcOpen = m.OpenProcess(ProcTextBox.Text);
                }
                else // if combobox set to ID, use integer
                {
                    ProcOpen = m.OpenProcess(Convert.ToInt32(ProcTextBox.Text));
                }
            });

            if (ProcOpen) // if process opens successfully
            {
                OpenProcessBtn.Invoke((MethodInvoker) delegate
                {
                    OpenProcessBtn.Text      = "Close Process";
                    OpenProcessBtn.ForeColor = Color.Red;
                });

                ModuleList.Invoke((MethodInvoker) delegate
                {
                    if (ModuleList.Items.Count <= 0)
                    {
                        GetModuleList();
                    }
                });
            }
            else // on process open fail, show error message
            {
                //MessageBox.Show("ERROR: Process open failed!");
                ProcStatus.Invoke((MethodInvoker) delegate
                {
                    ProcStatus.Text      = "Closed";
                    ProcStatus.ForeColor = Color.Red;
                });
                ModuleList.Invoke((MethodInvoker) delegate
                {
                    if (ModuleList.Items.Count > 0)
                    {
                        ModuleList.Items.Clear();
                    }
                });
                StopWorker = true;
            }
        }
Exemple #2
0
 private void BackgroundWork_DoWork(object sender, DoWorkEventArgs e)
 {
     // infinite loop that checks if the process is available and open, if not, modify the UI.
     while (true)
     {
         OpenTheProc();
         System.Threading.Thread.Sleep(1000);
         if (StopWorker)
         {
             StopWorker = false;
             OpenProcessBtn.Invoke((MethodInvoker) delegate
             {
                 OpenProcessBtn.Text      = "Close Process";
                 OpenProcessBtn.ForeColor = Color.Red;
             });
             break;
         }
     }
 }