473,809 Members | 2,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On process count change event?

Tyler Wiebe
66 New Member
I'm wondering if there is any event that my application can use to tell if a different process starts.

More specifically, I want to know when another process, let's say Notepad, appears in the System.Diagnost ics.Process.Get Processes(), and possibly when it disappears.

I'm mostly interested when the process appears, but when it disappears would be nice to.

Any information about this would be much appreciated.
Apr 22 '12 #1
3 2253
rekedtechie
51 New Member
im a newbie in c#
and im not sure..
but when i need to openread a file..
i code it like this.. :)

Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.IO;
  4.  
  5. public class tst
  6. {
  7. public static void main(string[] args)
  8. {
  9. FileStream fl1 = null;
  10. FileStream fl2 = null;
  11. try {
  12. fl1 = file.OpenRead("myfile1.txt");
  13. Console.WriteLine("fl1 open");
  14. fl2 = file.OpenRead("myfile2.txt");
  15. Console.WriteLine("fl2 open");
  16. }
  17. catch(Exception er)
  18. {
  19. Console.Write("{0}",er.toString());
  20. }
  21. finally
  22. {
  23. if(fl1 != null) {
  24. fl1.Close();
  25. Console.WriteLine("fl1 closed");
  26. }
  27. if(fl2 != null) {
  28. fl2.Close();
  29. Console.WriteLine("fl2 closed");
  30. }
  31. }
  32.  
  33. }
  34. }
  35.  
Apr 23 '12 #2
RhysW
70 New Member
rekedtechie, he isnt trying to open a file to read or write to, though his mention of notepad may have thrown you. If you open the task manager

(ctrl+alt+ecs keys)
and click the second tab along called Processes, the asker wants to be able to know when another process is added to this list, or removed.

On topic, This youtube video shows you how to make a basic task manager as do the related videos, whilst this isnt what you are looking for it will contain the code you need to use, instead of giving the code i gave the link as it will probably help to solve future questions about similar, yet different, problems, where this video covers many more than i could.
Apr 24 '12 #3
Tyler Wiebe
66 New Member
Well, thanks for the replies, and RhysW is correct, I am not trying to open a file. And yes, now that I think about it, saying Notepad may not have been the best example.

Anyway, this morning I wrote a simple quick function that can do what I want, however it's not exactly what I was asking for, but it gets the job done with no problems.
Expand|Select|Wrap|Line Numbers
  1.         public class Process
  2.     {
  3.         #region Constructors
  4.  
  5.         public Process(string Name)
  6.         {
  7.             this.Name = Name;
  8.             this.Timer.Start();
  9.         }
  10.  
  11.         #endregion
  12.         #region Events
  13.  
  14.         public event Handlers.Started Started;
  15.         public event Handlers.Ended Ended;
  16.  
  17.         #endregion
  18.         #region Functions
  19.  
  20.         private void Process_Update()
  21.         {
  22.             this.HasStarted = this.Exists;
  23.         }
  24.  
  25.         public bool Terminate()
  26.         {
  27.             try
  28.             {
  29.                 foreach (System.Diagnostics.Process Process in System.Diagnostics.Process.GetProcessesByName(this.Name))
  30.                 {
  31.                     Process.Kill();
  32.                 }
  33.                 return true;
  34.             }
  35.             catch { return false; }
  36.         }
  37.  
  38.         #endregion
  39.         #region Handlers
  40.  
  41.         public class Handlers
  42.         {
  43.             public delegate void Started();
  44.             public delegate void Ended();
  45.         }
  46.  
  47.         #endregion
  48.         #region Variables
  49.  
  50.         private System.Timers.Timer PTimer;
  51.         private System.Timers.Timer Timer
  52.         {
  53.             get
  54.             {
  55.                 if (this.PTimer == null)
  56.                 {
  57.                     this.PTimer = new System.Timers.Timer();
  58.                     this.PTimer.Interval = 1;
  59.                     this.PTimer.Elapsed += delegate { this.Process_Update(); };
  60.                 }
  61.                 return this.PTimer;
  62.             }
  63.         }
  64.  
  65.         public int Count
  66.         {
  67.             get { return System.Diagnostics.Process.GetProcessesByName(this.Name).Length; }
  68.         }
  69.         public bool Exists
  70.         {
  71.             get
  72.             {
  73.                 if (this.Count > 0) return true;
  74.                 else return false;
  75.             }
  76.         }
  77.         private bool PHasStarted;
  78.         private bool HasStarted
  79.         {
  80.             get { return this.PHasStarted; }
  81.             set
  82.             {
  83.                 if (this.PHasStarted != value)
  84.                 {
  85.                     this.PHasStarted = value;
  86.  
  87.                     if (this.PHasStarted && this.Started != null) this.Started();
  88.                     if (!this.PHasStarted && this.Ended != null) this.Ended();
  89.                 }
  90.             }
  91.         }
  92.  
  93.         public string Name { get; private set; }
  94.  
  95.         #endregion
  96.     }
  97.  

I'm not sure if this can be improved, but any improvements on this would be much appreciated.
Apr 24 '12 #4

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

Similar topics

2
17520
by: R. Rajesh Jeba Anbiah | last post by:
I have Googled a lot, but couldn't still find the answer... I could see, I can trigger the "click" event like: button_object.Click() But, I need to trigger the onChange() of select options. I couldn't find anything like: select_object.Change() More specifically, I have something like:
1
1586
by: muhamad kassem | last post by:
hi all i have a program that display the content of the table from sql server this table change . how i can get the change event in this table .
1
5674
by: djam | last post by:
Is there such a thing as a row change event in Win Forms? I can't seem to find anything similar, I'm using CurrentCellChanged but that gets fired mulitple times and its not the correct event for me to use. thanks Posted Via Usenet.com Premium Usenet Newsgroup Services ----------------------------------------------------------
3
7291
by: dave | last post by:
I have half a dozen web form radio buttons on a web form. Each of them is set to postback=true. However, if for instance radiobutton1 is already selected and the user selects it again, it performs a postback. I only want to do a postback if the value of the radiobutton is changed. What is the best method to accomplish this? thx dave
7
1677
by: Markus McGee | last post by:
Hi all, I have a quick question...I believe. On my web page, call it page A, I have a drop downlist with runat server enabled. When the drop downlist change event occurs it repopulates a table depending on the value selected on page A. After I redirect page A to some other page, call it page B, and use the IE Back button to change my selection on the page A the page is forwarded to page B without rebuilding the table on page A and...
1
8467
by: Carlos | last post by:
Hi all, I need to handle the checked change event for a radiobutton, but without the autopostback property set to true. Is that possible? The objective is to maintain the status of the same page, and only handling the event within the group of radiobuttons that I have defined inside the page. Thanks,
1
3524
by: Tony | last post by:
Hi, I have two forms A and B, both opened. In form A, I programmatically change the Date of Birth field of the current record of form B. I noticed that form B automatically displays the new data correctly. However, when I tried trapping the After Update, On Dirty, On Change, and On Current events of the Date of Birth text box, none of them gets triggered. I want to trap this change event so that in form B, I can programmatically...
0
1289
by: =?Utf-8?B?SiBTdHJlZ2Vy?= | last post by:
I have a procedure to increase/decrease the size of the columns in a datagrid proportional to their original size. I want to capture the event if a user manually resizes a column, so I can reset my percentages and save their changes. I know it has something to do with the TableStyles_CollectionChanged event, and that you need to add a column change event for the columns, but creating event handlers is new for me, so I need a bit of help....
3
2266
by: SimonG via AccessMonster.com | last post by:
Hi, I would like to be able to compare a control's new value with its old value, whenever it is changed by a user. The control holds a numeric value, qty_Sold, when this value changes I need to check its validity and apply appropriate actions. I have tried to do this using the control's 'On Change' event, and the properties '.Value' and '.Text' to return the control's old and new values. Unfortunately this event triggers on each...
2
11631
by: muddasirmunir | last post by:
I am using vb6. I want to solve one problem to define clearly i will use a simple example. Take a form and put a combobox in it Private Sub Form_Load() Combo1.AddItem "Apple"
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10391
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.