Determine whether the execution of the EXE is complete and the event listening

Source: Internet
Author: User

[Reprint] C # How to call the EXE file and how to determine if the EXE called by the program has ended
   
Original article address:C # How to call the EXE file and how to determine whether the EXE called by the program has ended Guoguo

A simple code can call the EXE file in C #, as shown below:

1. Introduce using system. diagnostics; Call code: process. Start (exe file name );

2. Directly system. Diagnostics. process. Start (exe file name ).

 

C # How to determine if the EXE called by the program has ended

Two Methods: Take the system notepad as an Example

Method 1: This method will block the current process until the running external program exits.
System. Diagnostics. Process exep = system. Diagnostics. process. Start (@ "C: windowsnotepad.exe ");
Exep. waitforexit (); // key. It can be executed only after the external program exits.
MessageBox. Show ("notepad.exe finished running ");

Method 2: Add an event monitor for an external process. After exiting, get the notification. This method does not block the current process. You can handle other tasks.
System. Diagnostics. Process exep = Newsystem. Diagnostics. Process ();
Exep. startinfo. filename = @ "C: \ WINDOWS \ notepad.exe ";
Exep. enableraisingevents = true;
Exep. exited + = new eventhandler (exep_exited );
Exep. Start ();

 

// Exep_exited event processing Code. The Code is activated after the external program exits and can be executed.
Void exep_exited (Object sender, eventargs E)
{

MessageBox. Show ("notepad.exe finished running ");
}

Determine whether the execution of the EXE is complete and the event listening

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.