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
2
votes
2 answers

get exception when show System.Windows.Forms.FolderBrowserDialog in wpf

I tried to show folderbrowserdialog in wpf but I got this exception Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This…
kartal
  • 17,436
  • 34
  • 100
  • 145
2
votes
2 answers

How to wait for completion of a call to ExecuteScript on a WebView2 interface in a C++ COM STA

I have an COM STA, that hosts an ICoreWebView2. I try to get the complete HTML block and I found a documentation to achieve this with a script. Here my code: hr = m_spWebView->ExecuteScript(L"document.body.outerHTML", …
xMRi
  • 14,982
  • 3
  • 26
  • 59
2
votes
2 answers

Questions about COM multithreading and STA / MTA

Hi I am a beginner in COM. I want to test a COM dll in both STA and MTA modes. My first question is: is it possible a COM object supports both STA and MTA? Now I imagine the STA code snippet below: // this is the main…
Charlie
  • 111
  • 2
  • 4
2
votes
1 answer

WPF: how to marshall data to user control from another domain

I have to use functionality that is in another application domain. The result should be displayed in user control. I have something like that: var instance = domain.CreateInstanceFromAndUnwrap(...); instance.Foo(myWpfUserControl as…
Andrew Florko
  • 7,672
  • 10
  • 60
  • 107
2
votes
1 answer

C# kill all processes started with Application.Run when main form closes

I am starting a bunch of invisible forms in seperate threads from my initial form with Thread thread = new Thread(() => { var form= new myform(); try { …
Samuel
  • 209
  • 1
  • 9
2
votes
1 answer

Blocking calls(wait, com calls) in STA thread

I have a windows service which creates 10+ threads which: do their job and then enter WaitForMultipleObjects state until they are resumed again .. each thread creates TDCOMConnection component calls method on its AppServer and then closes the…
Paul
  • 219
  • 3
  • 10
2
votes
1 answer

A STA threading mode thread also blocks the winform UI thread?

I am using a STA COM object from a back ground thread, one of the COM object's a method will block, when i call it from a new thread which is in STA threading mode since the COM object's mode is STA, and the UI thread seems gets blocked too, can i…
Benny
  • 8,547
  • 9
  • 60
  • 93
2
votes
1 answer

Calling STA COM object from WebApi

Is C#'s Runtime Callable Wrapper around a STA remote application type library safe (from the thread model and apartments perspective) to be called from a MTA thread context (.Net WebApi request)? Should I change the server STA application to MTA or…
EProgrammerNotFound
  • 2,403
  • 4
  • 28
  • 59
2
votes
1 answer

WPF Application class and main window initialization

I have public static int WindowCounter = 0; [STAThread] public static void Main() { ShowBeforeApplicationCreation(); //ShowAfterApplicationCreation(); } public static void ShowBeforeApplicationCreation() { ShowWindow(); …
user815512
  • 184
  • 1
  • 10
2
votes
0 answers

Multiple threads for StaTaskScheduler in ViewModel

ListBox contains list of files with their icons. I am trying to have 10 icons extracted at the same time but icons appear at same rate whether I have 1 of 10 as number of threads for StaTaskScheduler (TPL extensios). public class FileData :…
Daniel
  • 1,064
  • 2
  • 13
  • 30
2
votes
0 answers

Using Specflow and Watin - have set the STA-thread, still get a System.Threading.ThreadStateException

I'm writing UI-tests with Specflow and Watin. I have done the following to ensure Watin to work Setting the Thread.ApartmentState in the App.config
LenaS
  • 21
  • 1
2
votes
3 answers

Wpf application with multiple STA threads still blocks user interface

A while ago we added Python scripting to a Wpf application using IronPython. At first it was only 'slave' in the sense that a script was invoked by a button click for instance and then just ran to completion returning control to Wpf. Later on we…
stijn
  • 34,664
  • 13
  • 111
  • 163
2
votes
1 answer

UI freezes when using SystemEvents.UserPreferenceChanged and multiple UI threads

In my C# Windows Forms application there are two threads: Main Thread (Program.cs) WorkerClass Thread (STA-Apartment). When there is long running Task, it freeze/stuck the entire process and No exception or notification fired..it hangs…
Viral
  • 363
  • 2
  • 4
  • 14
2
votes
2 answers

Using WPF UI thread should always ensure STA apartment mode, right?

In my WPF application I communicate asynchronously with a server. The callback will hence not be run in the UI thread, and as I need to do some WPF stuff there (create InkPresenter object) I need it to be run on the UI thread. Well, actually the…
stiank81
  • 25,418
  • 43
  • 131
  • 202
2
votes
1 answer

vb.net problems with STAThread() Error: invalidOperationException

I want to make the function "createFolder" faster (or at least not blocking my main thread), by adding a new callback to my threadpool. I marked the main function with the STAThread() and the exception tells me to mark my main function with the…
MaBi
  • 1,372
  • 3
  • 13
  • 19