Vamsi Garuda

Vamsi Garuda

  • NA
  • 30
  • 0

Invoking excel object using threading from web services

Feb 25 2010 4:26 PM
Guys

I was trying to invoke a back ground process (mutli threaded env) from asp.net webservice in which excel object is used to calculate basing on define excel formula's. below is the code...


public

 

void SubmitBatchForPayrollProcessing(Int32 batchId)
{
 


//Spawn different thread and then return .....To have the tax processing done in background
 

this.batchId = batchId;
 


ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPayrollForBatch));
}

In turn ProcessPayrollForBatch function invokes excel object

this.exelProcessor = new ExcelProcessor();

I'm getting below error

An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/1/Root/PayrollService
Process ID: 2448
Exception: System.Runtime.InteropServices.COMException
Message: Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
StackTrace:    at Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)
   at JFA.IndiePay.BusinessAccess.ExcelProcessor..ctor() in C:\JFAFilms\Vertex\VertaxTest\BusinessAccess\ExcelProcessor.cs:line 23
   at PayrollService.PayrollService.ProcessPayrollForBatch(Object param) in C:\JFAFilms\Vertex\VertaxTest\PayrollService\PayrollService.asmx.cs:line 124
   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

---------------------

If I invoke excel object in a single thread env it was running as expected, but if I multi thread env I was getting above error.

Can any one help on this ?

Regards
MOhan