-1

But when build - The calling thread must be STA, because many UI components require this in first browser.MouseMove(x, y)

public MainWindow()
{
    // Initialize WPF Application UI.

    InitializeComponent();

    // Create WPF BrowserView component.
    browser = BrowserFactory.Create();

    browserView = new WPFBrowserView(browser);
    // Embed BrowserView component into main layout.
    mainLayout.Children.Add(browserView);
    browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
    {
        if (e.IsMainFrame)
        {
            int x = 100;
            int y = 10;
            browser.MouseMove(x, y);
        }
    };

    browserView.Browser.LoadURL("http://google.com");
}
kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • Because the code inside the event handler is running in a background thread, from a background thread you cannot access UI components directly, you need to wrap the code with Dispatcher.BeginInvoke (if you are using WPF). – kennyzx Sep 30 '18 at 11:07

1 Answers1

0

Try to wrap your code inside Dispatcher.BeginInvoke.

 if (e.IsMainFrame)
 {
      int x = 100;
      int y = 10;
      Dispatcher.BeginInvoke(new Action( ()=> {
          browser.MouseMove(x, y);
       }
 }
kennyzx
  • 12,845
  • 6
  • 39
  • 83