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.
3 2253
im a newbie in c#
and im not sure..
but when i need to openread a file..
i code it like this.. :) -
-
using System;
-
using System.IO;
-
-
public class tst
-
{
-
public static void main(string[] args)
-
{
-
FileStream fl1 = null;
-
FileStream fl2 = null;
-
try {
-
fl1 = file.OpenRead("myfile1.txt");
-
Console.WriteLine("fl1 open");
-
fl2 = file.OpenRead("myfile2.txt");
-
Console.WriteLine("fl2 open");
-
}
-
catch(Exception er)
-
{
-
Console.Write("{0}",er.toString());
-
}
-
finally
-
{
-
if(fl1 != null) {
-
fl1.Close();
-
Console.WriteLine("fl1 closed");
-
}
-
if(fl2 != null) {
-
fl2.Close();
-
Console.WriteLine("fl2 closed");
-
}
-
}
-
-
}
-
}
-
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.
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. -
public class Process
-
{
-
#region Constructors
-
-
public Process(string Name)
-
{
-
this.Name = Name;
-
this.Timer.Start();
-
}
-
-
#endregion
-
#region Events
-
-
public event Handlers.Started Started;
-
public event Handlers.Ended Ended;
-
-
#endregion
-
#region Functions
-
-
private void Process_Update()
-
{
-
this.HasStarted = this.Exists;
-
}
-
-
public bool Terminate()
-
{
-
try
-
{
-
foreach (System.Diagnostics.Process Process in System.Diagnostics.Process.GetProcessesByName(this.Name))
-
{
-
Process.Kill();
-
}
-
return true;
-
}
-
catch { return false; }
-
}
-
-
#endregion
-
#region Handlers
-
-
public class Handlers
-
{
-
public delegate void Started();
-
public delegate void Ended();
-
}
-
-
#endregion
-
#region Variables
-
-
private System.Timers.Timer PTimer;
-
private System.Timers.Timer Timer
-
{
-
get
-
{
-
if (this.PTimer == null)
-
{
-
this.PTimer = new System.Timers.Timer();
-
this.PTimer.Interval = 1;
-
this.PTimer.Elapsed += delegate { this.Process_Update(); };
-
}
-
return this.PTimer;
-
}
-
}
-
-
public int Count
-
{
-
get { return System.Diagnostics.Process.GetProcessesByName(this.Name).Length; }
-
}
-
public bool Exists
-
{
-
get
-
{
-
if (this.Count > 0) return true;
-
else return false;
-
}
-
}
-
private bool PHasStarted;
-
private bool HasStarted
-
{
-
get { return this.PHasStarted; }
-
set
-
{
-
if (this.PHasStarted != value)
-
{
-
this.PHasStarted = value;
-
-
if (this.PHasStarted && this.Started != null) this.Started();
-
if (!this.PHasStarted && this.Ended != null) this.Ended();
-
}
-
}
-
}
-
-
public string Name { get; private set; }
-
-
#endregion
-
}
-
I'm not sure if this can be improved, but any improvements on this would be much appreciated.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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 .
|
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
----------------------------------------------------------
|
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
|
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...
| |
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,
|
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...
|
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....
|
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...
|
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"
|
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...
| |
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,...
|
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |