c# - When to use [MTAThread]? -


possible duplicate:
could explain sta , mta?

in c# windows forms application. have seen [stathread] in program.cs above main function.

so want know when use sta or mta thread ?
how, affects application ?

a thread creates windows should always create single-threaded apartment. sta provides threading guarantees com object isn't thread-safe. few are. com infrastructure ensures methods of such object called right thread, marshaling call if necessary. quite similar control.begin/invoke() done automatically without coding.

a number of windows facilities rely on guarantee. notably clipboard, drag + drop , shell dialogs (like openfiledialog) won't work without it. , lots of activex controls, webbrowser being common 1 you'll use in winforms project. making ui thread mta thread causes hard diagnose failure, deadlock being common one. or quick exception when .net wrapper component double-checks created on sta.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -