sta

Difference between multi-threading vs multi-threading apartment?

烂漫一生 提交于 2019-12-12 03:39:44
问题 I am doing Multi-threading in single threaded apartment(STA) application. I am making an app that will load lot of data to the application which is making the application do not respond for long time. So I used multi-threading so that the application responds while loading so user can use other functionalities in it that are not related to loading data. My question is am I doing MTA inside STA application or just doing multi-threading in STA application? If so what is the difference between

Blocking method of an STA COM object is a design defect?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 05:01:11
问题 Say a COM object is created on an STA thread. So all calls to this object are serialized in this thread. So if a method of the object's is blocking, all threads that use this object are blocked. So having a blocking method in an STA COM object is a design defect to be avoided? If the COM object is free threading, it is OK to have a blocking method? Thanks 回答1: Yes, objects on single-threaded apartments are synchronized via messages and all calls to them are serialized in such way that no more

Why do I get an Invalid Operation Exception (non STA thread?) running this MSpec test on TeamCity?

↘锁芯ラ 提交于 2019-12-10 22:55:28
问题 As part of the migration of my app to .NET 4, I'm struggling to get some of the WPF unit tests working again with TeamCity. On all the tests that are somehow using a WPF control (a ListItem for example), I get an exception I didn't get before: System.InvalidOperationException: The calling thread must be STA, because many UI components require this. I understand what it means, and after checking, it turns out that my thread is indeed MTA, not STA. My problem is that I have no idea on how to

STATHREAD as async workflow in F#

社会主义新天地 提交于 2019-12-10 22:47:33
问题 Consider the following code fragment: let t1 = async { return process1() } let t2 = async { return process2() } let t3 = async { return windowsProcess() } let execute = [ t1; t2; t3 ] |> Async.Parallel |> Async.RunSynchronously |> ignore What to do in the case the windowsProcess requires a STATHREAD? Is this possible with this construction? 回答1: If there's a particular thread with a SyncrhonizationContext, e.g. the UI thread, then you could do e.g. // earlier on the UI thread... let syncCtxt

“The calling thread must be STA” workaround

谁说我不能喝 提交于 2019-12-08 23:56:33
问题 I know there are a few answers on this topic on SO, but I can not get any of the solutions working for me. I am trying to open a new window, from an ICommand fired from within a datatemplate. Both of the following give the aforementioned error when the new window is instantiated (within "new MessageWindowP"): Using TPL/FromCurrentSynchronizationContext Update: works public class ChatUserCommand : ICommand { public void Execute(object sender) { if (sender is UserC) { var user = (UserC)sender;

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

六眼飞鱼酱① 提交于 2019-12-08 03:14:25
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 usable. Do you know anything that could solve this problem? I am considering running two processes of my

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

99封情书 提交于 2019-12-07 15:34:32
问题 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) will do this for you while waiting for the object to be released by another thread. Another way of making .NET pump COM messages for you that I've seen is to use .Join(). Where can I find a complete list of built in threading primitives with this

Akka.net actors in STA

限于喜欢 提交于 2019-12-06 11:55:57
问题 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 instance make COM calls on this instance, like SaveAs(..) with paths from received messages from multiple parallel threads restart itself by any crash Is it even possible to run akka.net actor in STA? Is there any concerns if I use the akka.net this

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

懵懂的女人 提交于 2019-12-06 02:26:25
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) will do this for you while waiting for the object to be released by another thread. Another way of making .NET pump COM messages for you that I've seen is to use .Join(). Where can I find a complete list of built in threading primitives with this behaviour? Would waiting on a WaitHandle support this? What about WaitAny(), or the new concurrent

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