我正在努力访问浏览器帮助程序对象中异步httpwebrequest回调中的ui线程。当前的文档和窗口无法反射(reflect)调用线程中见证的内容,因此我无法根据需要更新UI。
有人可以帮忙吗?
干杯
最佳答案
我不确定您所处的上下文,但是在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();
}
关于c# - 如何在bho中的异步httpwebrequest回调中访问ui线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829385/