Threading problems with COm Interop
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

rajesh.sivakumar
I am using a third party COM componenet which is not thread safe in a .Net
web application using Interop. When two threads (two requests) are trying to
access the componenet it is giving an error and crashing. It works fine if
the request is made only one at a time. How can I code around this problem
so that only one thread operates on the COM object at one time.

Any help will be greatly appreciated.

Thanks
Rajesh

Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
rajesh.sivakumar <Click here to reveal e-mail address> wrote:
[Original message clipped]

Write a proxying class which locks a monitor during calls so that only
one thread can call the proxy method at a time.

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
    
Alvin Bruney [MVP]
just set the aspcompat flag to true for the document.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Jon Skeet [C# MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Paul Roberts
I had a similar problem interfacing with a vendors DLL. What I did was
create a mutex then only one thread can run the code at a time. I have
pasted in my functions below.

private void getBarraMutex()
{
barraMutex = new System.Threading.Mutex(false, "BarraInUseMutex");
barraMutex.WaitOne();
}

private void releaseBarraMutex()
{
if(barraMutex != null)
barraMutex.ReleaseMutex();
}

Hope that helps
Paul

"rajesh.sivakumar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
Paul Roberts <Click here to reveal e-mail address> wrote:
[Original message clipped]

Any reason not to use monitors instead? Unless you're worried about
multiple processes running the code at the same time, I think monitors
are a cheaper solution here. (They're also the more idiomatic .NET way
of locking.)

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
    
Paul Roberts
Yes we want to make sure that ony one process can run at one time. We also
have another application that needs to use the com component.

"Jon Skeet [C# MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Threading.Mutex




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com