473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

C# Process Monitoring

16
Im trying to monitor a process until the process ends but the program keeps freezing during the while loop and wont keep running. Heres what I have so far:

Expand|Select|Wrap|Line Numbers
  1. private void ProcessCheck()
  2.         { 
  3.             bool done = false;
  4.             while (!done)
  5.                 {
  6.  
  7.                  System.Diagnostics.Process[] myProcesses;
  8.             myProcesses =
  9.                System.Diagnostics.Process.GetProcessesByName("gsengine");   
  10.  
  11. if (myProcesses != null)
  12.                     {
  13.                         tabPage2.Enabled = false;
  14.                         tabPage3.Enabled = false;
  15.                         tabPage4.Enabled = false;
  16.  
  17.                         Start.Visible = false;
  18.                         stop.Visible = true;
  19.                         toolStripStatusLabel1.Text = "CORE RUNNING!";
  20.  
  21.  
  22.                 }
  23.  
  24.                     if (myProcesses == null)
  25.                     {
  26.  
  27.                         tabPage2.Enabled = true;
  28.                         tabPage3.Enabled = true;
  29.                         tabPage4.Enabled = true;
  30.  
  31.                         Start.Visible = true;
  32.                         stop.Visible = false;
  33.  
  34.                         toolStripStatusLabel1.Text = "CORE STOPPED FOR SOME REASON!";
  35.  
  36.                         done = true;
  37.                     }
  38.             }
  39.         }
Any ideas how I can get this working?
Feb 10 '08 #1
3 9627
kenobewan
4,871 Expert 4TB
The code here is not looping, obviously. One option is to set done to true and in case null set to false
Feb 10 '08 #2
Prodian
16
Ive used this method in other programs and it loops fine. I think the problem is the null part. If I put the done = true on both ifs it doesnt freeze but when its only on the == if, the program freezes.no errors. Is there another way Ican monitor to check to see if the process is still running?
Feb 10 '08 #3
Prodian
16
If anybody is interested I got this working as well, at first it was using 100% cpu until I added the Thread.Sleep:

Expand|Select|Wrap|Line Numbers
  1. private void StillRunning(object result)
  2.         {
  3.  
  4.  
  5.             if (!InvokeRequired)
  6.             {
  7.  
  8.                     Start.Visible = false;
  9.  
  10.                     stop.Visible = true;
  11.  
  12.                     tabPage2.Enabled = false;
  13.  
  14.                     tabPage3.Enabled = false;
  15.  
  16.                     tabPage4.Enabled = false;
  17.  
  18.                     toolStripStatusLabel1.Text = "GSMS STARTED!";
  19.  
  20.                     wizardToolStripMenuItem.Enabled = false;
  21.  
  22.  
  23.             }
  24.             else
  25.             {
  26.                 Invoke(new StillRunningHandler(StillRunning), result);
  27.  
  28.             }
  29.  
  30.         }
  31.         private void First_Thread()
  32.         {
  33.             Thread current_thread = Thread.CurrentThread;
  34.  
  35.             bool done = false;
  36.  
  37.             if (current_thread.IsAlive == true)  //Start of Thread is Alive
  38.             {
  39.                 while (!done)               //Start of While Loop
  40.                 {
  41.                    Process[] pname = Process.GetProcessesByName("gsengine");
  42.  
  43.                     Thread.Sleep(500);
  44.  
  45.                     if (pname.Length == 0)          //Core Stopped, Do this.
  46.                         {
  47.                            StoppedRunning(0);
  48.  
  49.                             current_thread.Abort();     //Stop Thread NOW
  50.  
  51.                             done = true;        //Get out of While Loop NOW
  52.                         }
  53.                     else                        //Core is running, Do this.
  54.  
  55.                         {
  56.  
  57.                         StillRunning(0);
  58.  
  59.                         }                    
  60.                 }           //End of While Loop
  61.             }               //End of If Thread is Alive
  62.  
  63.             else
  64.                 {
  65.                     toolStripStatusLabel1.Text = "Thread is not running, what happened?";
  66.                 }
  67.         }
  68.  
  69.         private void ThreadStart()
  70.         {
  71.             ThreadStart thr_start_func = new ThreadStart(First_Thread);
  72.             Thread fThread = new Thread(thr_start_func);
  73.             fThread.Name = "first_thread";
  74.             fThread.Start();    //starting the thread
  75.  
  76.         }
Feb 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ralf Gross | last post by:
Hi, I'm monitoring a RedHat Enterprise 4 server with a DB2 8.2 database. Last week I added some processes which should be checked, to the net-snmp config. db2fmcd db2fmp db2dasrrm db2fmd
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
2
by: Mike Fellows | last post by:
Hi, If i start a process using System.Diagnostics.Process.Start(myprog.exe, myattributes) is it possible to monitor that process from code so that i know when it has completed/closed? Thanks...
0
by: bamapookie | last post by:
I've written an app that starts and monitors a number of processes. If one of those processes dies, the app restarts it. One of the options I've written hides the main window of the monitored...
0
by: bamapookie | last post by:
I've written an app that starts and monitors a number of processes. If one of those processes dies, the app restarts it. One of the options I've written hides the main window of the monitored...
0
by: bamapookie | last post by:
I'm sorry if this was posted several times. I did not see my previous post appear after I posted it. I've written an app that starts and monitors a number of processes. If one of those...
0
by: Filipe Marcelino | last post by:
Hi, I whant to know if a user is using a process. To achieve that I have to know the state of the process, so I wrote the following code: Dim localAll As Process() =...
6
by: Laser Lu | last post by:
Thanks for looking at this post:) Does anyone knows how to make the asp.net process runs in the UserInteractive mode? I just want to show some Windows Forms in my asp.net application on the...
4
by: Paddy | last post by:
We have a recurring problem where a (long-running) service throws an exception while trying to access a file. The problem is that this is very rare (happens once every week and without warning) but...
1
by: nasha | last post by:
Hi, I am working with a test harness and I need to monitor a process. If the process isn't done in a specific alloted time, I need to abort the process. The code goes something like this... ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.