MultiThread Problem
-
Hi all! In my application I launch a third party application(AUT) to do some tests on it. From my application I launch the AUT in a separate thread so my application doesn't block. My application then analyzes the AUT in search for Clickable controls. I'm able to do this and no Thread has been thrown yet(please tell me if I'm being luck and I shouldn't be doing this). But then I want to programatically perform a click on that control. The way I'm trying to do it is using UIAutomation. So I try to create a AutomationElement from the control handle. That's when an InvalidOperationException is thrown saying I can't perform that operation because I'm doing it from a different Thread. I understand this and I've read the "Make Thread-Safe Calls to Windows Form Controls" How-To from Microsoft and the "What's up with BeginInvoke?" article but I haven't realize how to apply this knowledge to my problem. The reason is that the operation I'm trying to do is get the handle from a Control in a thir party application. Am I missing something? can someone shed some light on me please? Thanks, José Tavares
-
Hi all! In my application I launch a third party application(AUT) to do some tests on it. From my application I launch the AUT in a separate thread so my application doesn't block. My application then analyzes the AUT in search for Clickable controls. I'm able to do this and no Thread has been thrown yet(please tell me if I'm being luck and I shouldn't be doing this). But then I want to programatically perform a click on that control. The way I'm trying to do it is using UIAutomation. So I try to create a AutomationElement from the control handle. That's when an InvalidOperationException is thrown saying I can't perform that operation because I'm doing it from a different Thread. I understand this and I've read the "Make Thread-Safe Calls to Windows Form Controls" How-To from Microsoft and the "What's up with BeginInvoke?" article but I haven't realize how to apply this knowledge to my problem. The reason is that the operation I'm trying to do is get the handle from a Control in a thir party application. Am I missing something? can someone shed some light on me please? Thanks, José Tavares
jpsstavares wrote:
But then I want to programatically perform a click on that control.
jpsstavares wrote:
Am I missing something? can someone shed some light on me please?
Invoke works for a single process. It sounds like you have two processes so that is not going to work.
led mike
-
jpsstavares wrote:
But then I want to programatically perform a click on that control.
jpsstavares wrote:
Am I missing something? can someone shed some light on me please?
Invoke works for a single process. It sounds like you have two processes so that is not going to work.
led mike
led mike wrote:
Invoke works for a single process. It sounds like you have two processes so that is not going to work.
Well, actually no, I'm launching the application in another thread other than my main thread, but in the same process. Regarding the programatically clicking of a control, is there a way to do it (with UIAutomation or anything else)?
-
Hi all! In my application I launch a third party application(AUT) to do some tests on it. From my application I launch the AUT in a separate thread so my application doesn't block. My application then analyzes the AUT in search for Clickable controls. I'm able to do this and no Thread has been thrown yet(please tell me if I'm being luck and I shouldn't be doing this). But then I want to programatically perform a click on that control. The way I'm trying to do it is using UIAutomation. So I try to create a AutomationElement from the control handle. That's when an InvalidOperationException is thrown saying I can't perform that operation because I'm doing it from a different Thread. I understand this and I've read the "Make Thread-Safe Calls to Windows Form Controls" How-To from Microsoft and the "What's up with BeginInvoke?" article but I haven't realize how to apply this knowledge to my problem. The reason is that the operation I'm trying to do is get the handle from a Control in a thir party application. Am I missing something? can someone shed some light on me please? Thanks, José Tavares
You have to click the Button on the same thread as it was created, otherwise you'll get this exception. For normal applications that means that all UI components are created on the main (UI) thread and all calls to the UI coming from background threads have to be marshaled back to the UI thread, either by using Control.Invoke or a SynchronizationContext. In your szenario, either run the 3rd party software on the UI thread and your tasks on a background thread, then you can use Invoke or a SynchronizationContext, or really be sure that everything you call to the 3rd party app is on the same worker thread. Regards Urs
-^-^-^-^-^-^-^- no risk no funk
-
led mike wrote:
Invoke works for a single process. It sounds like you have two processes so that is not going to work.
Well, actually no, I'm launching the application in another thread other than my main thread, but in the same process. Regarding the programatically clicking of a control, is there a way to do it (with UIAutomation or anything else)?
jpsstavares wrote:
Well, actually no, I'm launching the application in another thread other than my main thread, but in the same process.
No. Launching an application will produce a new process for that application. Unless you mean something different than "launching an application".
-
jpsstavares wrote:
Well, actually no, I'm launching the application in another thread other than my main thread, but in the same process.
No. Launching an application will produce a new process for that application. Unless you mean something different than "launching an application".
Yeah sorry, I wasn't explicit. I'm "launching" the application by Executing its assembly with AppDomain.CurrentDomain.ExecuteAssembly(filePath);