.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

stathread, mtathread

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :WPF
What is STAThread, MTAThread... I remember .NET CF didnot support MTAThread... why main() is decorated with them...
- Rajesh K http://thoughtsontechies.blogspot.com/

View Complete Post

More Related Resource Links

what is accomplished by decorating a C-Sharp Main Subroutine with MTAThread vs. STAThread.


Can you please tell what is accomplished by decorating a C-Sharp Main Subroutine with MTAThread vs. STAThread.

I have read couple C-Sharp Multithreading books, but I did not find any explanation of applicability of STAThread or MTAThread in C sharp code.

Why are such attributes needed in a C-sharp code in the first place ?

I had a Console Application where its Main was decorated with STAThread by default. Everything worked without problem. Then I added a WCF service, which services a separate GUI Client application. When I use the GUI, my Console application gives a ContextSwitchDeadlock error. The only way I can get rid of the error is by marking the MAIN MTAThread. But I do not why the error goes away. 

Also, My Console Application does use a COM Based service, but I do not know if that has a bearing on this problem or not.

Help appreciated. 

Thank you

media player crashes if winforms is mtathread


On creating media player control in my winforms whose main() function is marked as mtathread... i get below error ActiveX control '6bf52a52-394a-11d3-b153-00c04f79faa6' cannot be instantiated because the current thread is not in a single-threaded apartment. But I dont want to change my threading model as some other activex controls are involved...

First of all why it did crash... this article from Jeff Prosise says "if an MTA thread creates a ThreadingModel=None or ThreadingModel=Apartment object, calls from that thread will be marshaled from the MTA to the object's STA." http://www.codeguru.com/cpp/com-tech/activex/apts/article.php/c5529 Why marshaling didnt happen and instead app crashes when the thread creating com object is .NET thread?

I am just creating the media player control not even operating with multiple threads...

I am creating media player control from .net winforms whose main is marked as [MTAThread]... thats all I see a crash... why instantiation is crashes... (atleast I should be able to create and later if control crashes because of operating play(), pause() from multiple threads it makes sense)

- Rajesh K http://thoughtsontechies.blogspot.com/
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend