Why Mistake - when simulate mouse in dotnetbrowser?

105 Views Asked by At

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");
}
1

There are 1 best solutions below

0
On BEST ANSWER

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);
       }
 }