C# 捕获操作后,WebBrowser挂起在加载中

C# 捕获操作后,WebBrowser挂起在加载中,c#,browser,C#,Browser,我正在开发使用WordCaptureX和WebBrowser组件的应用程序 应用程序处理热键,从屏幕捕获单词,并将WebBrowser控件导航到某个url。期望用户可以从应用程序WebBrowser捕获一个单词,但在多次捕获操作后,控件挂起在加载状态,导航方法无法工作。我试图阻止WebBrowser,甚至处理它并重新创建,但没有任何帮助 我创建了一个带有主要应用程序操作的演示 public partial class Form1 : Form { private readonly WMo

我正在开发使用WordCaptureX和WebBrowser组件的应用程序

应用程序处理热键,从屏幕捕获单词,并将WebBrowser控件导航到某个url。期望用户可以从应用程序WebBrowser捕获一个单词,但在多次捕获操作后,控件挂起在加载状态,导航方法无法工作。我试图阻止WebBrowser,甚至处理它并重新创建,但没有任何帮助

我创建了一个带有主要应用程序操作的演示

public partial class Form1 : Form
{
    private readonly WMonitorX _wMonitor = ComFactory.Instance.NewWMonitorX();
    private readonly WCaptureX _wCapture = ComFactory.Instance.NewWCaptureX();

    private readonly ManualResetEvent _runCaptureEvent = new ManualResetEvent(true);
    private readonly ManualResetEvent _startRetrieveEvent = new ManualResetEvent(false);

    private int _hwnd;
    private int _x;
    private int _y;

    private delegate void Worker();
    private readonly Worker _worker;

    public Form1()
    {
        InitializeComponent();

        _wMonitor.LineColor = 11119017;
        _wMonitor.LineWidth = 10;
        _wMonitor.WEvent += _wMonitor_WEvent;
        _wMonitor.Start((int)W_KEY.wmKeyCtrl, (int)W_MOUSE.wmMouseRight, false);

        webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;

        _worker = RunCaptureAndNavigate;
        _worker.BeginInvoke(null, null);
    }

    private void _wMonitor_WEvent(int hwnd, int x1, int y1, int x2, int y2)
    {
        _hwnd = hwnd;
        _x = x1;
        _y = y1;

        _startRetrieveEvent.Set();
    }

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (e.Url == webBrowser1.Url)
        {
            _runCaptureEvent.Set();
            toolStripStatusLabel1.Text = "Page loaded";
        }
    }

    private void RunCaptureAndNavigate()
    {
        while (true)
        {
            _startRetrieveEvent.WaitOne();
            _runCaptureEvent.WaitOne();

            _runCaptureEvent.Reset();
            _startRetrieveEvent.Reset();

            Invoke((MethodInvoker) ExecuteCapturing);

            Invoke((MethodInvoker) Activate);

            toolStripStatusLabel1.Text = "Page loading";
            webBrowser1.Navigate("google.com");
        }
    }

    private void ExecuteCapturing()
    {
        var input = ComFactory.Instance.NewWInput();
        input.Hwnd = _hwnd;
        input.StartX = _x;
        input.StartY = _y;
        input.Options = (int) W_CAPTURE_OPTIONS.wCaptureOptionsHighlightWords |
                        (int) W_CAPTURE_OPTIONS.wCaptureOptionsUseWindowsWordBreaking;

        var result = _wCapture.Capture(input);

        var text = string.Empty;
        if (result != null && string.IsNullOrEmpty(result.Text))
        {
            text = result.Text;
        }

        textBox1.Text = text;
    }
}
不幸的是,对WordCaptureX组件的支持不能帮助我避免浏览器在加载时出现死机的情况

那么,有没有人知道如何重新初始化浏览器