C # Start and end a thread

Source: Internet
Author: User

In the program execution will encounter the launch of the software EXE asked, or enable other EXE files, has achieved the role of some operations performed. Here are two of the most common startup exe files.

1. Call the system DLL using the method it provides.

The referenced DLL,

[CSharp]View Plaincopyprint?
    1. [DllImport ("kernel32.dll")]
    2. public static extern int winexec (string exename, int opertype);

Called, winexec (@ "path \exe filename", parameter);

The opertype parameters are as follows:

[CSharp]View Plaincopyprint?
    1. 0: Hidden, and the taskbar does not have a minimized icon
    2. 1: Display with the nearest size and position, activate
    3. 2: Minimize, activate
    4. 3: Maximize, activate
    5. 4: Display with the nearest size and position, do not activate
    6. 5: Same 1
    7. 6: Minimize, do not activate
    8. 7: Same 3
    9. 8: Same 3
    10. 9: Same 1
    11. 10: Same 1

2, the most common ProcessStartInfo start-up

[CSharp]View Plaincopyprint?
    1. ProcessStartInfo info = new ProcessStartInfo ();
    2. Info.              filename = @"path \exe file name";
    3. Info.              Arguments = "";
    4. Info. WindowStyle = processwindowstyle.minimized;
    5. Process Pro = Process.Start (info);
    6. Pro. WaitForExit ();

3. End the process of starting EXE

[CSharp]View Plaincopyprint?
  1. process[] Allprogresse = System.Diagnostics.Process.GetProcessesByName ("EXE's process name");
  2. foreach (Process closeprogress in allprogresse)
  3. {
  4. if (closeProgress.ProcessName.Equals ("EXE's process name"))
  5. {
  6. Closeprogress.kill ();
  7. Closeprogress.waitforexit ();
  8. Break ;
  9. }
  10. }

C # Start and end a thread

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.