my application uses Microsoft.Office.Interop.Excel service to generate an excel report and download as PDF as well. If more than one user requests the same page i:e; same service then the first user is able to get the result but the later one generates some Exception. Can we avoid this by providing each users with individual threads i:e; if one is running then other have to wait for some seconds.
Here are my code:
protected void btn2games_Click(object sender, ImageClickEventArgs e)
{
myfilepath = "acd.xlsx";
try
{
string sr = Server.MapPath(myfilepath.ToString());
if (File.Exists(myfilepath))
{
File.Delete(myfilepath);
}
}
catch
{
}
ExceltoPdf();
}
protected void ExceltoPdf()
{
//here the code goes : to fetch data from DB and write to Excel using Office.Interop.Excel
}
The Office libraries are not licensed for server use (last I checked), and the COM Interop interface is not thread-safe. It's unwise to try to use them in a web application.
Licensing issues aside, you could create a queueing system that allows requests to be submitted to the system (maybe a Windows Service) that processes the requests either one at a time, or perhaps spins up a number of child processes (not threads... processes) to concurrently process several requests.
It's probably not worth that Engineering effort, though. If you Google "Excel to PDF" you will find quite a few third-party components that are meant to be used in a server environment. I cannot recommend any specific one for lack of direct experience.
Thanks in Advanc - Jyoti 2012-04-04 13:06
For pdfs I've been using DynamicPdf its been working well - mortb 2012-04-04 08:30