获取在Visual Studio中运行的主(用户界面)线程处理。
命名空间: Microsoft.VisualStudio.Data.Core
程序集: Microsoft.VisualStudio.Data.Core(在 Microsoft.VisualStudio.Data.Core.dll 中)
语法
声明
ReadOnly Property UIThread As Thread
Thread UIThread { get; }
property Thread^ UIThread {
Thread^ get ();
}
abstract UIThread : Thread
function get UIThread () : Thread
属性值
类型:System.Threading.Thread
在Visual Studio中运行的主(用户界面)线程处理。
备注
此属性用于确定代码是否适用于Visual Studio的主线程当前正在运行的进程。这通常很有用被调用 InvokeOnUIThread 或避免动态委托的开销的 BeginInvokeOnUIThread 调用方法。
示例
下面的代码演示如何 UIThread 属性的典型用法确定在UI线程必须运行的方法是否直接调用或必须动态调用在线程间的调用。
using System;
using System.Threading;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Shell.Interop;
public class DdexHostSvcExample2
{
public static void UpdateUI(IVsDataHostService hostService)
{
if (Thread.CurrentThread == hostService.UIThread)
{
// Called on UI thread, directly call method
ActuallyUpdateUI(hostService);
}
else
{
// Called from background thread, begin invoke on UI thread
hostService.BeginInvokeOnUIThread(
new UpdateUIDelegate(ActuallyUpdateUI),
hostService);
}
}
private delegate void UpdateUIDelegate(IVsDataHostService hostService);
private static void ActuallyUpdateUI(IVsDataHostService hostService)
{
IVsUIShell uiShell = hostService.GetService<IVsUIShell>();
uiShell.UpdateCommandUI(0); // fImmediateUpdate == false
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。