Free Support Forum - aspose.com

Locked objects in multiuser environments

Hi

Practical question: I have an application used by n persons and one single .doc template that is opened and filled with text and then passed on to the browser. When two users opens the document at the same time I get System.InvalidOperationException: Object is currently in use elsewhere. Logical, but how would you handle this problem? By waiting and trying again? Any other solution?

I think you should create a unique copy of the template document for each user. It is not good that several users are trying to open the same document. Although I don't understand completely how it happens in your scenario. Do you have a template somehwere on LAN and several users from different computers on the network are trying to open it simultaneously?

This is a web application that web users access. The template is of course read from the disk locally to which the web application has rights. It is impossible to create each user an unique document because I simply do not know who is going to open it. I open and use it with the following code:

Protected Sub buttSaveWord_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttSaveWord.Click
Dim tstr As String
Try
If Not ViewState("CurrentDocumentHTML") Is Nothing Then
tstr = System.Configuration.ConfigurationManager.AppSettings("PathTemplates") & "WordTemplate.doc"
Dim doc As Document = New Document(tstr)
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
tstr = ViewState("CurrentDocumentHTML").ToString
builder.InsertHtml(tstr)
RoutinesWords.removeHyperlinkFormatting(doc)
doc.Save("QAForms.doc", SaveFormat.FormatDocument, SaveType.OpenInWord, Response)
End If
Catch ex As Exception
....
End Try
End Sub

I am not sure that it is Aspose.Words that causes exception and that exception is caused by openning the document. Please step through the code with debugger to find out exactly what line is causing the exception and also please attach the full text of exception with a stack trace.

Best regards,

Yes, it does not look like a problem with reading the same file at the same time. Aspose.Words is designed to be used on the server and there will be no such problem. When reading, Aspose.Words opens a file in read only mode and does not require exclusive access to the file. Also, it opens the file only for the short period of time that it takes to load the file, then closes it. Make sure you don’t have this file open in Microsoft Word when you are trying to open it in Aspose.Words since Microsoft Word makes an exclusive open of the file. Vladimir is right, pPost the stack trace here if you want more help from us.

Hi

We noticed this error when we tested our application with 5 users on our server. There is no chance that the file was open with Word becuse no-one that tested had rights to this document. Could the doc.save cause a problem?. Don't know how to get a trace from our "live" site except the error message we have coded which is:

Error: System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, PointF origin, StringFormat stringFormat)
at ᘎ.ᘭ.ᘸ(String _ߥ, Font أ)
at ᘎ.ᘭ.ᘱ(Paragraph ᘲ)
at ᘎ.ᘍ.ᘞ(Cell ᘟ)
at ᘎ.ᘍ.ᘘ()
at ᘎ.ᘍ.ᗤ(Boolean ᗥ)
at Aspose.Words.Table.ᗤ(Boolean ᗥ)
at ᛒ.᜶.᜺(ۭ ہ, Boolean ᜻)
at ᛒ.ᛑ.ᛤ(ۭ ہ, Boolean ᛣ)
at ᛒ.ᛑ.ᛢ(ۭ ہ, Boolean ᛣ)
at ᛒ.ᛑ.ᛟ(ۭ ہ)
at ᛒ.ᛑ.ᛟ(ۭ ہ)
at ᛒ.ᛑ.ᛟ(ۭ ہ)
at ᛒ.ᛑ.ᛠ(پ ᛡ)
at Aspose.Words.DocumentBuilder.InsertHtml(String html)
at qa.QAData.buttSaveWord_Click(Object sender, EventArgs e)

Hi,

Thanks for reporting this to us. We will fix this problem until v4.0 final is out. I've logged this issue as #1268.

We have made a fix for it in Aspose.Words 4.0. Please download and try with this new version.

Best regards,