Excel application in ASP. NET: (13) optimization (continued)

Source: Internet
Author: User

The preceding chapter describes how to use automation to Operate Excel. Each time new excel. Application () is used. In this way, each time you access excel, you need to start an Excel instance, which takes a lot of time to start Excel (in my environment, it usually takes 15 seconds to start Excel ). This can be optimized by declaring the Excel. application type variable as static. In this way, in addition to starting Excel for the first time, other Excel instances will not be started in subsequent operations. In this way, there will be only one Excel instance, saving space, it also saves "cold" time to start excel. In my development environment, you can reduce the original 22 seconds to 7.3-7.5 seconds, which is equivalent to saving about 2/3 of the time!

Implementation exampleCodeAs follows:

Static excel. application _ excelapp = new excel. application ();... public void finalize () // The {_ excelapp to be destroyed at the end. quit (); releasecomobject (_ excelapp); _ excelapp = NULL; GC. collect (0 );}

Do not manually kill excel. EXE in the memory (for example, use the task manager to kill it). Otherwise, the next time you call the Excel Code, an error will occur because the object has crashed.

 

 

 

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.