sta

How to run NUnit test in STA thread?

匆匆过客 提交于 2020-01-24 19:27:35
问题 We are in the process of porting a WPF app to .NET Core 3, preview 5. Some NUnit tests need to run in STA threads. How can this be done? None of the attributes like [STAThread], [RequiresSTA], ... work. This also doesn't work: [assembly: RequiresThread(ApartmentState.STA)] The Apparent namespace does not seem to be exposed in .NET Core 3. Has anyone done this? 回答1: ApartmentAttribute was first enabled for .NET Standard 2.0 in NUnit 3.12. First update your version of the NUnit framework, then

UI freezes when using SystemEvents.UserPreferenceChanged and multiple UI threads

落花浮王杯 提交于 2019-12-25 03:52:30
问题 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 application. Internally applications doing processing of records only (selection from SQL tables & inserting in Access DB tables) UI updates will be done using event Action feature. Find attached snap for stuck process parallel tasks. Seems like threads

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

好久不见. 提交于 2019-12-25 03:25:12
问题 I know, there are a lot of similar questions on SO. But I have pretty strange situation: I get this exception while it is executed inside Dispatcher.CurrentDispatcher.Invoke. I have no idea how to fix it. Here is my StackTrace (you can see dispatcher is called there): at System.Windows.Input.InputManager..ctor() at System.Windows.Input.InputManager.GetCurrentInputManagerImpl() at System.Windows.Input.KeyboardNavigation..ctor() at System.Windows.FrameworkElement.FrameworkServices..ctor() at

C# WebBrowser Error Thread

独自空忆成欢 提交于 2019-12-25 02:18:56
问题 I am having trouble getting a web browser in my form to work. When I run, I get this error ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. It takes me to the form designer.cs file to this text this.webBrowser2 = new System.Windows.Forms.WebBrowser(); and I really do not know what to do to get thebrowser working. I have tried both MTAThread and STAThread in the Program.cs file cant seem to get it to

STA or MTA for indirectly used COM Objects

孤街浪徒 提交于 2019-12-24 18:15:20
问题 I think I understand the apartment concept and why STA or MTA is used, however a question came up for which I found no solution so far. If my application uses COM Objects under the hood, for example from third party libraries, how do I know if I can use MultiThreaded-Appartment (MTA)? In that case, I have no Idea if those objects are thread safe, so do I need to go with STA, just to be on the safe side? 回答1: Your ability to use certain COM interface pointer on STA or MTA thread code depends

STA Thread is not loading the Main Window in WPF

不想你离开。 提交于 2019-12-24 08:51:05
问题 I am loading MainWindow in App_Startup (). I wanted to show the progress bar while loading the window. But it is not working : void App_Startup(object sender, StartupEventArgs e) { Thread bootStrapThread = new Thread(new ThreadStart(runBootStrapProcess)); bootStrapThread.SetApartmentState(ApartmentState.STA); bootStrapThread.IsBackground = true; bootStrapThread.Start(); _loadingProgressBar = new loadingProgressBar(); _loadingProgressBar.ShowDialog(); } I want to load the window from thread :

Process.Start is blocking

大城市里の小女人 提交于 2019-12-23 08:57:27
问题 I'm calling Process.Start, but it blocks the current thread. pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe"); // Start process mProcess = new Process(); mProcess.StartInfo = pInfo; if (mProcess.Start() == false) { Trace.TraceError("Unable to run process {0}."); } Even when the process is closed, the code doesn't respond anymore. But Process.Start is really supposed to block? What's going on? (The process start correctly) using System; using System.Diagnostics; using System.Threading;

Is possible having two COM STA instances of the same component?

有些话、适合烂在心里 提交于 2019-12-23 02:40:51
问题 I had a problem discovered on another thread here, I need to access a COM component that is STA. I'll run it on a dual-core computer, a process using this component only reaches 50% of CPU. Unfortunately, the owners said they can't change the component to MTA, because the component is a hybrid system compiled at Matlab, which core is C. So I tried to load two instances of the COM class on the same process, different threads accessing it, but I couldn't, only the last COM instance becomes

COM outbound call results in “An outgoing call cannot be made since the application is dispatching an input-synchronous call.”

守給你的承諾、 提交于 2019-12-20 10:24:03
问题 I have a COM server (C++/STA (MFC based app)) and a COM client (C#/MTA). The COM server must live in an STA, since it's an MFC app (I have no choice in this matter). The client issues a call to the server, and the server issues a callback to the client. That's where the error happens ( RPC_E_CANTCALLOUT_ININPUTSYNCCALL ). I'm guessing if the server had been an MTA, this problem would never have arised, but sadly, the documentation for MFC explicitly denies initializing the apartment as an MTA

Is Powershell -sta (apartment state) preferred?

喜夏-厌秋 提交于 2019-12-19 05:58:24
问题 I've been dabbling in Powershell (2.0) for the past several months and would love to use it to modernize and standardize some of the processes at work - mostly DOS based processes. Because of the nature of the work, there could be around 100 executions of the same script(s) going at once. First--Is Powershell "safe" to use in this manner? I have seen -STA as an execution option - is that the preferred method of working with Powershell when executing a good number of the same script