Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. MultiThread Problem

MultiThread Problem

Scheduled Pinned Locked Moved Windows Forms
helptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jpsstavares
    wrote on last edited by
    #1

    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

    L U 2 Replies Last reply
    0
    • J jpsstavares

      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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • L 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

        J Offline
        J Offline
        jpsstavares
        wrote on last edited by
        #3

        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)?

        L 1 Reply Last reply
        0
        • J jpsstavares

          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

          U Offline
          U Offline
          Urs Enzler
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • J jpsstavares

            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)?

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            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".

            J 1 Reply Last reply
            0
            • L led mike

              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".

              J Offline
              J Offline
              jpsstavares
              wrote on last edited by
              #6

              Yeah sorry, I wasn't explicit. I'm "launching" the application by Executing its assembly with AppDomain.CurrentDomain.ExecuteAssembly(filePath);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups