简体   繁体   English

如何在BHO中的异步httpwebrequest回调中访问ui线程

[英]How can I access the ui thread in an asynchronous httpwebrequest callback in a bho

I'm struggling to get access to the ui thread in an asynchronous httpwebrequest callback in a browser helper object. 我正在努力访问浏览器帮助程序对象中异步httpwebrequest回调中的ui线程。 The current document and windows don't reflect those witnessed on the calling thread, so I can't update the UI as required. 当前的文档和窗口无法反映调用线程中见证的内容,因此我无法根据需要更新UI。

Can anyone help? 有人可以帮忙吗?

Cheers 干杯

I'm not certain what context you're in, but in WinForms, you can access the main Form's UI thread from another thread with form.Invoke() like this: 我不确定您所处的上下文,但是在WinForms中,您可以使用form.Invoke()从另一个线程访问主Form的UI线程,如下所示:

        // Assuming the following Form and method:
        Form form = ...
        Action method = ...

        // Invoke the method like this, so it is run in the UI thread.
        if (form.InvokeRequired)
        {
            form.Invoke(method);
        }
        // If we are already in the UI thread, 
        // just run the method without an invoke.
        else 
        {
            method();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM