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
5
votes
1 answer

WPF with Windows Forms - STAThread

I am a newbie to WPF and have a couple of questions about WPF and Windows Forms integration. I have an existing Visual C# Windows Forms application. I would like to integrate it with a WPF window, that can be shown on a button click. This was not…
user26242
  • 93
  • 1
  • 9
5
votes
2 answers

Cannot use a DependencyObject that belongs to a different thread than its parent Freezable - prism

I have came across a problem while developing a WPF application. The application is based on Prism. The application boots using the prism bootstraper and before loading any Window, the app opens a modal dialog on a different thread (STA), and then…
benchuk
  • 669
  • 7
  • 13
4
votes
1 answer

Unable to set WinForms clipboard in unit test

I'd like to populate the Forms.Clipboard with text from a NUnit test. The first problem I encountered was that the Clipboard must be used in STA mode. I found the solution (NUnit 2.5.x+) to set the RequiresSTA attribute on the method. Next I get an…
Torbjörn Kalin
  • 1,976
  • 1
  • 22
  • 31
4
votes
5 answers

Waiting for clipboard text change (error)

I'm trying to detect every time the clipboard data changes. And so, I set a timer and have it continuously check Clipboard.GetText() for changes. I'm using the following code: public void WaitForNewClipboardData() { //This is in WPF, Timer comes…
mattsven
  • 22,305
  • 11
  • 68
  • 104
4
votes
2 answers

Is it possible to await Thread in C#

I am in a situation where I have to spawn a new thread manually, so I am able to can call .SetApartmentState(ApartmentState.STA). This means (as far as I know) that I cannot use Task. But I would like to know when the thread was done running,…
Jakob Busk Sørensen
  • 5,599
  • 7
  • 44
  • 96
4
votes
2 answers

Why is Task.Delay breaking the STA state of the thread?

Introduction This is a lengthy question! You will find some background on the problem at the beginning, then code samples, which have been simplified for representation and the Question after that. Please read in any order that you find good for…
ful-stackz
  • 302
  • 4
  • 10
4
votes
1 answer

Form behaving weirdly when using STA and threads take too long

We're developing a multithreaded game engine in C#, and we got the problem that we need the STAThread attribute (or set our threads to STA manually) to enable drag-and-drop support (AllowDrop can't be set without STA). However, when we enable STA…
georch
  • 959
  • 7
  • 18
4
votes
3 answers

Defining STA: "single thread affinity" or "single threaded apartment"; and how they relate

I'm working with WPF and am reading through materials on STA. Two questions: 1) STA is defined as standing for both "single thread affinity" and "single threaded apartment" by different articles. This says the…
user603563
  • 374
  • 3
  • 15
4
votes
4 answers

How to access COM object within a BackgroundWorker?

I have a WPF app and in the main form, user is allowed to select few files(Excel) and then click a button to do a data extraction and uploading them to a database. Things work fine. Now I wanted to implement a busy indicator. So what I have done…
voddy
  • 950
  • 1
  • 11
  • 21
4
votes
4 answers

Will COM marshalling be (ever) neccessary for an object with ThreadingModel Both?

This is triggered by another question. Specifically, I have a in process COM class, that is defined in the CLSID registry as having a ThreadingModel of Both. Our process activates this object through CoCreateInstance (not CoCreateInstanceEx, if that…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
4
votes
2 answers

NUnit async test + RequiresSTA => await not returning on STA thread

The below code: [RequiresSTA] [Test] public async Task TestSta() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId+" - "+Thread.CurrentThread.GetApartmentState()); // *** await something here *** …
Olivier
  • 5,578
  • 2
  • 31
  • 46
4
votes
1 answer

VSTO Background Threading with STA and COM

I'm building a VSTO add-in: I need to run a background thread, but this thread needs to access COM components (I've implemented IMessageFilter to make this messaging as safe as possible). All threads which access OLE or COM have to be STA I believe;…
user1713993
  • 113
  • 2
  • 7
4
votes
2 answers

Why STAThread attribute is ignored?

vs strange behavior … Hi, All! Could anyone explain me, how could it be? Thanks, Alex.
Alex
  • 131
  • 8
3
votes
3 answers

Aspcompat in ASPX Page

In my aspx pages, I call a COM component that uses STA. So I use aspcompat=true parameter, but I want to understand the logic. What does it exactly do? As far as I know, in STA, it is assumed to be called only by one thread. So I should provide the…
Feyyaz
  • 3,147
  • 4
  • 35
  • 50
3
votes
0 answers

Registration-Free COM not playing nice with single threaded objects. Activation context dropped during marshaling

I'm working on integrating a COM/CLI based library into a Java based application through JNI (yeah, it's a bit of a mess). For the most part it's working, but I've hit a bit of a snag when it comes to how activation contexts interact with single…
finalman
  • 774
  • 5
  • 14
1 2
3
15 16