BITS in STAs and MTAs

Dec 15, 2012 at 3:45 PM

So far I was unsure whether BITS can run in a Multi Threaded Apartment (MTA). Even BitsManager tries to set the apartment state to STA (but this is actually not working since the apartment state can only be defined before a thread is started). I asked on stackoverflow and got an excellent answer by Hans Passant (

According to this BITS works in both threading models. If using an MTA one must "only" ensure that his own programming is thread safe.

Just wanted to share this information.

Dec 16, 2012 at 7:51 AM

Thanks for sharing!

As you noticed in BitsManager code, it's trying to set the apartment state to STA, but wouldn't fail running in MTA as well, and the SharpBits code should be thread safe as far as concerning the BITS COM interface operations.

If I remember correctly, setting the STA option was introduced to avoid some common mistakes, similar to what your referenced thread describes. The original SharpBITS code was written on .NET 1.1 platform and a few features may have changed/improved since then, so this particular section seem to be a candidate for review or just being obsolete now (but doesn't fail or render the code unusable).