apartment-state

ASP.Net WebApi STA Mode

心已入冬 提交于 2019-12-23 17:04:09
问题 This post scratches off WebApi from being able to run in STA mode. But this post is also 2 years old. I've been digging into the newer WebApi2 but can't seem to find a way to make MessageHandlers run in STA mode. So has anyone found a way of running WebApi or WebApi2 in STA mode? 回答1: So it seems that if you want to switch the entire request processing thread to STA mode, you're better off with MVC. However, if your handler does a one off task that doesn't involve switching the entire thread

Winforms: One COM object needs an STAThread, the other needs an MTAThread. How can I use them?

让人想犯罪 __ 提交于 2019-12-22 17:39:40
问题 I'm trying to build a Winforms application with two COM components. However, one of the components only works when using [MTAThread] and the other only works with [STAThread] . What would the recommended solution be? 回答1: Windows forms requires [STAThread] to be present on it's main entry point. It will only work in Single threaded apartment state. You can use your STA COM object on the UI thread in Windows Forms, with no issues. The typical approach for this is to create your own thread, and

The calling thread must be STA, because many UI components require this WPF

北城以北 提交于 2019-12-12 23:08:02
问题 I am using the MessageBox provided by WPF Toolkit. And I get the error The calling thread must be STA, because many UI components require this new Thread(new ThreadStart(delegate { MessageBox.Show("Opeartion could not be completed. Please try again.","Error",MessageBoxButton.OK,MessageBoxImage.Error); })).Start(); How can I set the ApartmentState in this case Edit: I am trying to display a modeless MessageBox using MessageBox control of WPF Toolkit. So far the code I have is as follows: void

How to Query the COM Apartment State for the Current Thread

吃可爱长大的小学妹 提交于 2019-12-11 02:15:51
问题 The .NET Thread class has a handy function GetApartmentState() that returns the apartment of context of the thread. Is there a similar Co<something-something> function for native code (C++, C)? I feel like I should know, since I've been programming COM for almost 10 years, but I cannot find the answer. 回答1: The function you're looking for is CoGetApartmentType. 来源: https://stackoverflow.com/questions/15981228/how-to-query-the-com-apartment-state-for-the-current-thread

How to check apartment state of current thread?

99封情书 提交于 2019-12-04 15:27:40
问题 I have a function which requires to be run in STA apartment state. I wan't to check if it is being run as STA, and if not spawn a new thread which runs in STA. How can I check which apartment state the current thread is being run in? 回答1: System.Threading.Thread.CurrentThread.GetApartmentState() 回答2: Use this or a similar method inside the function: System.Threading.Thread.CurrentThread.GetApartmentState 来源: https://stackoverflow.com/questions/2378379/how-to-check-apartment-state-of-current

How to check apartment state of current thread?

纵然是瞬间 提交于 2019-12-03 09:36:28
I have a function which requires to be run in STA apartment state. I wan't to check if it is being run as STA, and if not spawn a new thread which runs in STA. How can I check which apartment state the current thread is being run in? Marek System.Threading.Thread.CurrentThread.GetApartmentState() Use this or a similar method inside the function: System.Threading.Thread.CurrentThread.GetApartmentState 来源: https://stackoverflow.com/questions/2378379/how-to-check-apartment-state-of-current-thread