我如何在一个异步httpwebrequest回调中访问ui线程?

本文关键字:回调 httpwebrequest 访问 ui 线程 异步 一个 | 更新日期: 2023-09-27 18:03:25

我在浏览器helper对象中的异步httpwebrequest回调中努力访问ui线程。当前的文档和窗口不能反映调用线程上看到的那些,所以我不能按要求更新UI。

有人能帮忙吗?

欢呼

我如何在一个异步httpwebrequest回调中访问ui线程?

我不确定你在什么情况下,但在WinForms,你可以访问主窗体的UI线程从另一个线程与form.Invoke()这样:

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