[C #] how to end the Excel Process

Source: Internet
Author: User

Many people often see posts on how to end the Excel process in forums.
The method is to first obtain the system process list, and then match "Excel", which is Excel
The process is killed, I personally think this method is not feasible, if the software uses this method
Killing processes started by yourself is a Bug (it is possible to kill the Excel process ).
I found another way to kill the Excel process on the Internet, as shown below:
System. Runtime. InteropServices. Marshal. ReleaseComObject (worksheets );
System. Runtime. InteropServices. Marshal. ReleaseComObject (worksheet );
...
System. Runtime. InteropServices. Marshal. ReleaseComObject (excelApp );
System. Runtime. InteropServices. Marshal. ReleaseComObject (range );
Worksheets = null;
Worksheet = null;
...
ExcelApp = null;
Range = null;
Release all the object instances used to operate Excel files.
Then the resources are recycled!
GC. Collect ();
The above code is best placed in finally to prevent the Excel file from being executed due to exceptions!
Open the task manager and check if the excel process is no longer there!
If any of you have a better method, please contribute and learn together!

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.