我很难在浏览器帮助程序对象的异步httpwebrequest回调中访问ui线程。当前文档和窗口不反映在调用线程上见证的那些,因此我无法根据需要更新UI。
有人可以帮忙吗?
干杯
答案 0 :(得分:3)
我不确定你所处的上下文,但是在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();
}