Free Support Forum - aspose.com

How to resolve "The object is currently in use elsewhere." error?

Hi,

I am evaluating Aspose.Slides Version 2.5.0.0. I have a requirement to generate multiple slides programatically based on a PPT template. My sample code is working fine for single thread. When I try to run with multiple threads it's giving "The object is currently in use elsewhere" run time error.

Please find the Stack Trace below:

Line 177: this.Response.ContentType="application/vnd.ms-powerpoint";
Line 178: string strfilename="demo_"+Guid.NewGuid().ToString()+".ppt";
Line 179: this.Response.AppendHeader("Content-Disposition","attachment;filename="+strfilename);
Line 180: mypres.Write(st);
Line 181: this.Response.End();
Line 182:
Source File: c:\inetpub\wwwroot\pptaspose\webform1.aspx.cs Line: 180

Stack Trace:

[InvalidOperationException: The object is currently in use elsewhere.]
   System.Drawing.Graphics.MeasureString(String text, Font font, PointF origin, StringFormat stringFormat)
   ঝ.ಚ.ಱ(೬ ಲ, ೬ ಳ, Portion ಴, Single& ವ)
   ঝ.ಚ.ಯ(Boolean ರ)
   ঝ.ಚ..ctor(Graphics Graphics, Paragraphs Text, ૪ Fonts, Single Width, Boolean WrapText, AnchorText Anchor, Tabs Tabs, Color BackgroundColor)
   Aspose.Slides.TextFrame.ಌ()
   Aspose.Slides.TextFrame.get_಄()
   Aspose.Slides.Table.಍()
   Aspose.Slides.Rectangle.಍()
   Aspose.Slides.Shape.਷()
   Aspose.Slides.Presentation.਷(Boolean ਸ਼)
   Aspose.Slides.Presentation.Write(Stream stream)
   pptaspose.WebForm1.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\pptaspose\webform1.aspx.cs:180
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()



Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Looking for your help. Appreciate for quick response.

Thanks

Sreedhar.

Dear Sreedhar,

You shouldn’t access one presentation from different threads.
Most of operations with presentation are too large to be synchronized.
But different threads can work with different presentations simultaneously.

Hi Alex,

I'm not trying to access same presentation with multiple threads. For every thread i'm creating the new file name using Guid object. Please find the source code bleow:

this.Response.ContentType="application/vnd.ms-powerpoint";
string strfilename="demo_"+Guid.NewGuid().ToString()+".ppt";
this.Response.AppendHeader("Content-Disposition","attachment;filename="+strfilename);
mypres.Write(st);
this.Response.End();

Looking forward to your help.

Thanks,

Sreedhar.

“mypres” object. Is it used from multiple threads or from one thread only?

For each thread a new mypres object will be created. Please find the source code below:

string strpath=Server.MapPath("./myfile.ppt");
FileStream fs = new FileStream(strpath,FileMode.Open,FileAccess.Read,FileShare.Read);
Presentation mypres = new Presentation(fs);
int c = mypres.Slides.Count;

fs.Close();

Please find my sample code as attachment. Whenever I'm trying this code from two browsers the second browser always giving this error. This is happening on my dev server which doesn't have MS Office.

This can be great help if you can resolve this issue.

Thanks..

Dear Sreedhar,

We have fixed the problem. Please try 2.5.1 hot fix and write about results.

Hi,

I am testing the App. As of now no issues. Any how I'll let you know the results once I'm done with my thorough testing.

Thanks for the hot fix!

Sreedhar.

The threading issue has been solved. Now it is working fine. Thanks for the hot fix.

Sreedhar.