sta

What are the limitations of a STA thread in compare to MTA threads?

℡╲_俬逩灬. 提交于 2019-12-03 11:24:13
问题 If we make a thread STA like this: Thread.SetApartmentState(STA); then it cannot run code marked with [MTAThread] attribute. We have seen [STAThread] in windows and console applications but I have never seen code with [MTAThread] attribute and don't know which .NET libraries use this attribute. My question is what are the limitations of a thread with apartment state set to STA, in compare to threads with MTA apartment state (natural .NET threads) ? 回答1: then it cannot run code marked with

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

What are the limitations of a STA thread in compare to MTA threads?

我怕爱的太早我们不能终老 提交于 2019-12-03 01:45:01
If we make a thread STA like this: Thread.SetApartmentState(STA); then it cannot run code marked with [MTAThread] attribute. We have seen [STAThread] in windows and console applications but I have never seen code with [MTAThread] attribute and don't know which .NET libraries use this attribute. My question is what are the limitations of a thread with apartment state set to STA, in compare to threads with MTA apartment state (natural .NET threads) ? then it cannot run code marked with [MTAThread] attribute. That's not how it works. The apartment type is a property of a thread, not of a method.

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

ぃ、小莉子 提交于 2019-12-02 21:05:09
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. Any ideas on how to work around this problem? I have been toying with the idea of letting the server

The calling thread must be STA, because many UI components require this error In WPF. On form.show()

孤者浪人 提交于 2019-11-30 18:57:00
Firstly I have read several answers to similar questions on the site but to be honest I find them a bit confusing (due to my lack of experience rather than the answers!). I am using a the FileSystemWatcher() class to monitor a folder for a file being created/changed. Once the event occurs I then want to load another form in the project. Instead of loading the form I get the error when the constructor on the new form is trying to execute. I am only using one thread - I'm not attempting to load the form under a different thread. My code is as follows //MainWindow public static void FolderWatcher

The calling thread must be STA, because many UI components require this error In WPF. On form.show()

廉价感情. 提交于 2019-11-30 03:17:27
问题 Firstly I have read several answers to similar questions on the site but to be honest I find them a bit confusing (due to my lack of experience rather than the answers!). I am using a the FileSystemWatcher() class to monitor a folder for a file being created/changed. Once the event occurs I then want to load another form in the project. Instead of loading the form I get the error when the constructor on the new form is trying to execute. I am only using one thread - I'm not attempting to load

Is there a way to programmatically set the ApartmentState to STA?

一个人想着一个人 提交于 2019-11-29 20:08:12
问题 I'm working on a GUI in PowerShell where I was throwing errors when certain comboboxes were clicked. After the error was thrown, I could drop the combobox list down and see it's contents, but if I shifted to another combox on the same datagridview, I would get the same initial error before I could see the drop-down list. I posted this in the TechNet PowerShell forums and got the answer that I needed to run my GUI in single threaded apartment (STA). PowerShell, by default, runs in MTA but you

Convert Keith Hill's PowerShell Get-Clipboard and Set-Clipboard to a PSM1 script

微笑、不失礼 提交于 2019-11-29 03:55:19
I'd like to convert Keith Hill's C# implementation of Get-Clipboard and Set-Clipboard into pure PowerShell as a .PSM1 file. Is there a way to spin up an STA thread in PowerShell as he does in his Cmdlet when working with the clipboard? The Blog Post The Code hoge TextBox doesn't require -STA switch. function Get-ClipBoard { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Paste() $tb.Text } function Set-ClipBoard() { Param( [Parameter(ValueFromPipeline=$true)] [string] $text ) Add-Type -AssemblyName System.Windows.Forms $tb =

An MTA Console application calling an STA COM object from multiple threads

旧城冷巷雨未停 提交于 2019-11-28 20:48:56
Although there are many questions about COM and STA/MTA (e.g. here ), most of them talk about applications which have a UI. I, however, have the following setup: A console application, which is by default Multi-Threaded Apartment (Main() explicitly has the [MTAThread] attribute). The main thread spawns some worker threads. The main thread instantiates a single-threaded COM object. The main thread calls Console.ReadLine() until the user hits 'q', after which the application terminates. A few questions: Numerous places mentions the need of a message pump for COM objects . Do I need to manually

Expression or reg-ex for java script or adobe livecycle tools

隐身守侯 提交于 2019-11-28 14:24:27
What will be the expression for restricting a user to enter either 5 lines or 375 characters in a scrollable text field? I tried theese: ([A-Z])\w+ $0</a> var re,regs,val; if(OTHER.rawValue!=null) { val=OTHER.rawValue; //re=[a-zA-Z\d\s\-\,\#\.\+]+ //re=/abc(?!$){5}/ re=/\be(\w*)s\b/m{2,10}$; regs=val.match(re); if(!regs) { fieldname.rawValue=""; xfa.host.messageBox("ANY THING"); xfa.host.setFocus(fieldname) } } re=/abc(?!$){5}/ and many more... but I am not getting exact one to validate either 5 lines or 375 characters Try this: ^((.+\n){0,4}.+|.{1,375})$ $(document).ready(function() { $("