C # How to start an external program,

Source: Internet
Author: User

C # How to start an external program,

1. Start an external program without waiting for it to exit. 2. Start the external program and wait for it to exit. 3. Start an external program and wait for it to exit. 4. Start an external program and monitor its exit through the event. // Using System. diagnostics; private string appName = "calc.exe"; // <summary> // 1. start an external program and do not wait for it to exit /// </summary> private void button#click (object sender, EventArgs e) {Process. start (appName); MessageBox. show (String. format ("external program {0} started completely! ", This. appName), this. text, MessageBoxButtons. OK, MessageBoxIcon. information);} // <summary> // 2. start the external program and wait for it to exit. // </summary> private void button2_Click (object sender, EventArgs e) {try {Process proc = Process. start (appName); if (proc! = Null) {proc. WaitForExit (3000); if (proc. HasExited) MessageBox. Show (String. Format ("external program {0} has exited! ", This. appName), this. Text, MessageBoxButtons. OK, MessageBoxIcon. Information); else {// forcibly terminate an external program if it has not ended. Proc. Kill (); MessageBox. Show (String. Format ("external program {0} was forcibly terminated! ", This. appName), this. text, MessageBoxButtons. OK, MessageBoxIcon. exclamation) ;}} catch (ArgumentException ex) {MessageBox. show (ex. message, this. text, MessageBoxButtons. OK, MessageBoxIcon. error); }}/// <summary> // 3. start an external program and wait for it to exit. // </summary> private void button3_Click (object sender, EventArgs e) {try {Process proc = Process. start (appName); if (proc! = Null) {proc. WaitForExit (); MessageBox. Show (String. Format ("external program {0} has exited! ", This. appName), this. text, MessageBoxButtons. OK, MessageBoxIcon. information) ;}} catch (ArgumentException ex) {MessageBox. show (ex. message, this. text, MessageBoxButtons. OK, MessageBoxIcon. error); }}/// <summary> // 4. start an external program and monitor it through the event to exit /// </summary> private void button4_Click (object sender, EventArgs e) {try {// start the external program Process proc = Process. start (appName); if (proc! = Null) {// monitor the process to exit proc. enableRaisingEvents = true; // specifies the exit event Method proc. exited + = new EventHandler (proc_Exited) ;}} catch (ArgumentException ex) {MessageBox. show (ex. message, this. text, MessageBoxButtons. OK, MessageBoxIcon. error); }}/// <summary> /// start the external program exit event // </summary> void proc_Exited (object sender, EventArgs e) {MessageBox. show (String. format ("external program {0} has exited! ", This. appName), this. Text, MessageBoxButtons. OK, MessageBoxIcon. Information );

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

Related Article

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.