[C #] Ways to end the process of Excel

Source: Internet
Author: User
excel| process in the forum often see asked how to end the Excel process of posts, many people give
The method is to get a list of system processes and then match "Excel", which is Excel
The process of killing, I personally think that this method is not feasible if the software in this way
Killing your startup process should be a bug (it's possible to kill the user Excel process).
I found another way to kill the Excel process on the Web, as follows:
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;

Releases all the object instances used by the operation Excel file.

Then recycle the resources!
Gc. Collect ();

The above code is best to put in finally, prevent the operation of Excel files when an exception occurs and cannot be executed!

When you open Task Manager, see if the Excel process is gone!

Which friend if has the better method, also please contribute out, everybody studies together!



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.