using threads per user to access a common service

Go To StackoverFlow.com

0

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

}
2012-04-04 08:22
by Jyoti
Try to get some third party components that will create your excel sheets and PDFs instead...Installing Excel in your production environment and getting it to run soomthly has historically (according to accounts from collegues) been a pain...

For pdfs I've been using DynamicPdf its been working well - mortb 2012-04-04 08:30

Please share the exception with us. Is this a web app or client app - Slugart 2012-04-04 08:30


1

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.

2012-04-04 08:30
by Eric J.
Client is not interested to buy any third party tools. Hence I've to go this way. My application is working perfectly and efficiently. The only thing is I've to make it run for more than one concurrent users for rare cases (Maximum users are <= 4 as these users are admins). I think it can be done by using individual Threads for each User (I am not sure abt this). Any help is greatly appreciated.......

Thanks in Advanc - Jyoti 2012-04-04 13:06

Ads