Home > Net >  C # to get the end events
C # to get the end events

Time:09-26

An EXE, can be open for many times, only one process, how to use c # for a program was turned off,,,

CodePudding user response:

 
Using System. Diagnostics;

Process the processes []=Process. GetProcesses ();
Foreach (Process p in the processes)
{
Console. WriteLine (p.P rocessName);
P.K ill ();//close the corresponding process of name
}

Process. The Start (" ");//to open the process of absolute paths are shown in brackets

CodePudding user response:

As the second floor, in the loop body class judge whether there is open process, not, say, was shut down,

CodePudding user response:

reference 1st floor Bridge_go response:
 
Using System. Diagnostics;

Process the processes []=Process. GetProcesses ();
Foreach (Process p in the processes)
{
Console. WriteLine (p.P rocessName);
P.K ill ();//close the corresponding process of name
}

Process. The Start (" ");//to open the process of absolute paths are shown in brackets


B: no, I want to learn that a program is turned off, a EXE, can open run many times, but only one process, I need to know which a few is turned off

CodePudding user response:

Process has been open, just EXE can open multiple forms, which form is turned off, I want no matter a few forms, they all only one process

CodePudding user response:

Oh, looks like a little bit of a problem, or, alternatively, your process, only one, to open, and then alarm prompt, don't get out of the way, how do?

CodePudding user response:

You put all of the form is set to global variables, only to open this one, and then, through the global variables, determine the form to have open,

CodePudding user response:

Such as you to the Program. The definition of cs
 public static Query WindowQuery; 

Then you start the other window the window
 Program. WindowQuery=new Query (); 
The Program. The WindowQuery. ShowDialog ();

Then judge whether the window is closed, null said closing
 if (Program. WindowCloseQuery==null) 

CodePudding user response:

Be turned off? Exe is turn off two kind of situations:
1 is closed, notified the operating system, for example, their normal ended;
2 is forcibly terminated, namely the Kill off by the operating system;
The first case of controlled (similar to suicide), can be dealt with in the code, once the end is to write a log of what (suicide before a note); The second is uncontrolled, like him, you don't have the chance to write a note,

CodePudding user response:

A similar Application. ApplicationExit events,

CodePudding user response:

Reference
an EXE, can be open for many times, only one process deficiency


This can only indicate he did a mutually exclusive operation

Want to judge him off a few as to what you say, we don't need to decide right, the other party mutually exclusive operation is written in the program. The cs, he didn't do what matter, just a mutex, we judge he doesn't make sense, it is invalid proposition

Reference
process has been open, just EXE can open multiple forms, which form I want to be turned off, no matter a few forms, they have only one process

The form and processes is not a thing, if it is the request, suggest to hang hooks, monitored wm_close message interception

CodePudding user response:

refer to 7th floor andy_wanhl response:
such as you to the Program. The definition of cs
 public static Query WindowQuery; 

Then you start the other window the window
 Program. WindowQuery=new Query (); 
The Program. The WindowQuery. ShowDialog ();

Then judge whether the window is closed, null said closing
 if (Program. WindowCloseQuery==null) 

I am obtaining third-party software, I want to know what time the third party software is turned off
  •  Tags:  
  • C#
  • Related