none
InvokePattern.Invoke() or simple click does not call InvokedEvent handler RRS feed

  • Question

  • Hello to all!

    I have next situation:

    1. Application A: WinForms application with one button;
    2. Application B: Console application with automation functionality;
    3. I set AutomationEventHandler with AutomationEvent InvokePattern.InvokedEvent and perform Automation.AddAutomationEventHandler;
    4. Application B do not catch invoke event of Application A when I perform InvokePattern.Invoke() or simple click on button of Application A.

    Sample of code:

    Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, uiControl, TreeScope.Element, new AutomationEventHandler(OnUIAutomationEventHandler)); Thread.Sleep(5000); var invokePattern = uiControl.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke();

    // Or here I make click.

    Thread.Sleep(5000); Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, uiControl, uiaEventHandler);

    private static void OnUIAutomationEventHandler(object sender, AutomationEventArgs e)
    {
         Console.WriteLine("INVOKED!");
    }


    Additional information: if Application A is WPF then all work good that I am think problem is related to WinForms.

    Please, help to understand what could be the problem.

    Thanks in advance!



    Wednesday, November 27, 2019 12:35 PM

All replies

  • Hi folkwulf, 

    Thank you for posting here.

    According to your description, I try to make a test, but I need more information.

    Could you provide some related code about ‘uiControl’ and ‘uiaEventHandler’? It will help us to make a test.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 29, 2019 9:56 AM
  • Hi Xingyu Zhao,

    I get uiControl in the following way:

    var uiControl = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "button1"));

    Button information in the WinForms application is as follows:

    this.button1 = new System.Windows.Forms.Button();

    // // button1 // this.button1.Location = new System.Drawing.Point(218, 40); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(84, 23); this.button1.TabIndex = 31; this.button1.Text = "TEST Button"; this.button1.UseVisualStyleBackColor = true;

    this.Controls.Add(this.button1);


    That is all.


    • Edited by folkwulf Monday, December 2, 2019 11:00 AM
    Monday, December 2, 2019 9:21 AM
  • Hi folkwulf, 

    Thanks for your feedback.

    For your question, you find that InvokePattern.Invoke() does not call InvokedEvent handler.

    I find a related reference about ‘InvokePattern.Invoke’, and you can refer to the suggestions in them.

    Hang with InvokePattern - Invoke

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 5, 2019 2:06 AM
  • Hi Xingyu Zhao,

    Thank you for trying to help me. But "Hang with InvokePattern - Invoke" does not solve my issue. I known about specific feature of modal windows.

    In my case the button does nothing. And I am just trying catch InvokedEvent to WinForms using automation. Also this construction works good to WPF.

    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

    Sincerely,

    folkwulf.

    Thursday, December 5, 2019 9:20 AM