Questions tagged [sta]

Single-Threaded Apartment of the Component Object Model (COM), as opposed to MTA

STA refers to the Single-Threaded Apartment of Microsoft's Component Object Model (COM). Its opposite is the Multiple Threaded Apartment (MTA), but there is also a Neutral Apartment.

Related tags:

References:

230 questions
3
votes
1 answer

Which blocking threading operations in .NET will handle COM messages when blocked?

When creating a new STA thread to host an STA COM component, it is the responsibility of that thread to pump Windows messages related to COM. From what I've been able to gather, certain built in .NET threading primitives such as lock (Monitor.Enter)…
SoftMemes
  • 5,602
  • 4
  • 32
  • 61
3
votes
0 answers

Working with WPF window created in another (STA)Thread

I'm writing an Excel Addin, from which I want to display WPF Windows. Launching these on the Main Thread ( = Excel's calculation thread) seems to mess up Excel, so I need to launch them in a seperate (STA-)Thread. What I'm struggling with is how to…
Bogey
  • 4,926
  • 4
  • 32
  • 57
3
votes
1 answer

Open 2nd WPF window in another thread?

With the code below, I am able to generate a 2nd window but the 2nd window closes itself as soon as it initializes. What am I doing wrong here? private void button_Click(object sender, RoutedEventArgs e) { Thread sta = new…
BioExtract
  • 79
  • 2
  • 8
3
votes
1 answer

Akka.net actors in STA

I need to convert thousands of ms office documents in different formats into one common format. To get things faster i would parallelize it using akka.net for. The WordSaveAsActor should: run in Single-Threaded Appartment hold the Word Application…
python_kaa
  • 1,034
  • 13
  • 27
3
votes
1 answer

Switching between STAThread and MTAThread and memory leaks

While looking for a memoryleak in a vb.net WebService, I detected that finalizers where blocked, and so several objects where never released (e.g. System.Threading.ReaderWriterLock) Google told me that this might be, because the STAThread Attribute…
DanielG
  • 1,217
  • 1
  • 16
  • 37
3
votes
1 answer

How will STAThread affect my multi-threaded program

I've recently encountered a STA-related error in my program when I tried to launch an OpenFileDialog in a WinForm. I've done some reading, and before I add the [STAThread] attribute to my main thread I want to know how it will affect my program's…
valsidalv
  • 761
  • 2
  • 19
  • 33
3
votes
1 answer

Managed WPF and native code interop. WPF hosted in ServicedComponent

I'm struggling to host WPF application in ServicedComponent. I have a WPF library, which I need to use from native code. In order to reach this goal, I created a outproc COM+ component, put all WPF calls in it and call this component from the native…
Anton K
  • 4,658
  • 2
  • 47
  • 60
3
votes
2 answers

STA call from MTA

I am just starting to deal with STA/MTA issues, so apologies for the simplicity of the question. I couldn't find an answer I could actually understand at the bottom of the ladder here. I am writing a plugin for another piece of software, and come…
Aaron Marcus
  • 153
  • 2
  • 13
3
votes
2 answers

Multiple VB6 apartments in C# application

We have very old legacy vb6 application, that has one global object that serves as Application Core, that stores different application settings, invokes database operations and so on. Multiple modules with different progid use this global object and…
Aloraman
  • 1,389
  • 1
  • 21
  • 32
3
votes
1 answer

Thread must be STA-Thread, but it already is

Im working on my thesis about an C# WPF program, but i ran into an error i dont understand. Somewhere in my MainWindow Code im starting a new Thread like this: Thread searchServer = new Thread(new ThreadStart(doSearchServer)); …
Maaaario
  • 93
  • 2
  • 7
3
votes
1 answer

Why is Thread.Join not letting through COM messages?

I am running some multi-threaded code that does the following. On an STA thread, I create a 'worker' thread, and run it. The STA thread then waits for the worker thread to exit. The worker thread calls a method on a proxy to an STA COM object on…
mackenir
  • 10,801
  • 16
  • 68
  • 100
3
votes
1 answer

ActiveX control cannot be instantiated because thread is in a single-threaded apartment. Happens after waking PC from sleep

I am working on a VOIP client (Window's form) that opens a browser window (ExtendedWebBrowser) when a call is made or received. Normally it works fine but if the computer is put into sleep mode and then woken the program will crash with the…
2
votes
1 answer

Best practice for calling an STA Visual Basic 6.0 COM object in a WCF service: Concurrent access

I have a WCF service which calls an STA Visual Basic 6.0 COM object. Everything works normally if only one client is using the service, but as soon as concurrent users start to call it, I'm in trouble and getting all kinds of random errors when…
user405723
  • 481
  • 3
  • 7
  • 21
2
votes
2 answers

Microsoft's Aparment Analogy (STA, MTA): Need help understanding it

I've read lots about the Microsoft's threaded apartment model, but I'm still having a little trouble visualizing it. Microsoft uses the analogy of living things living in an apartment. So, for STA, consider the following (I know it's a little…
Verax
  • 2,409
  • 5
  • 27
  • 42
2
votes
1 answer

Is it possible to apply attribute to the generated main method in a top-level application?

C#9 supports top-level statements, but I am curious whether it is possible to apply any attribute to generated main method (STAThread, actually), or I have to use classical approach with Main method.
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137