Sign in to follow this  
Followers 0
Aki999

C# ActiveX and Threading Issues

2 posts in this topic

I have the following code sample:

AutoItX3 autIt = new AutoItX3();

autIt.AutoItSetOption("WinTitleMatchMode", 2);

autIt.Sleep(500);

autIt.WinWait("MyTitle", "", 0);

This works perfectly if I execute this code in an own thread. But if I execute from within the WindowMessage thread (for example within the button click event) it does not find the dialog with MyTitle.

Ok I have a workaround - just start by a thread.

But then I have another issue. I want to log the AutoIt executions on to my gui. So within the thread a I have to do a BeginInvoke and assign the log text to the control which shows the log. After the BeginInvoke call I have trouble again with AutoItX3.

AutoItX3 autIt = new AutoItX3();

autIt.AutoItSetOption("WinTitleMatchMode", 2);

MyTextBox.BeginInvoke(new SetMyTextDelegate(SetMyText), "Click OK");

autIt.Sleep(500);

autIt.WinWait("MyTitle", "", 0);

autIt.WinActivate("MyTitle");

autIt.Sleep(500);

string result = autIt.ControlCommand("MyTitle", "", "[TEXT:&OK]", "IsEnabled", "");

Without the BeginInvoke call result is "1" with the call it is "0".

My OS: Windows 7 64-Bit.

Do you have any ideas how to solve this problem?

Thank you!

Share this post


Link to post
Share on other sites



COM is meant to be contained in single threaded models and not used cross thread.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0