Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

Threading problems with COM Interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rajesh.sivakumar - 09 Sep 2004 07:12 GMT
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
Rick Strahl [MVP] - 09 Sep 2004 07:23 GMT
Rajesh,

If you have control over the thread that the COM object runs on create that
thread with ApartmentState to STA. This should allow the COM object to work
properly and create individual instances on separaet threads.

This is likely the only way you will get this to work - STA style COM
objects will get corrupted if called from a free threaded environment if
more than one thread accesses this object. STA will make sure that the COM
object always gets marshalled to the thread that created it.

+++ Rick ---

Signature

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web

> 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
[quoted text clipped - 6 lines]
> Thanks
> Rajesh
Willy Denoyette [MVP] - 09 Sep 2004 22:51 GMT
Make sure you set aspcompat attribute to true in your aspx page
<%@ Page aspcompat="true" ...%>

Willy.

>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
[quoted text clipped - 7 lines]
> Thanks
> Rajesh

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.