IVsDataHostService.BeginInvokeOnUIThread 方法
以非同步方式執行以 Visual Studio 處理序 的主要 (UI) 執行緒上執行指定的方法,以指定的引數清單。
命名空間: Microsoft.VisualStudio.Data.Core
組件: Microsoft.VisualStudio.Data.Core (在 Microsoft.VisualStudio.Data.Core.dll 中)
語法
'宣告
Function BeginInvokeOnUIThread ( _
method As Delegate, _
ParamArray args As Object() _
) As IAsyncResult
IAsyncResult BeginInvokeOnUIThread(
Delegate method,
params Object[] args
)
IAsyncResult^ BeginInvokeOnUIThread(
Delegate^ method,
... array<Object^>^ args
)
abstract BeginInvokeOnUIThread :
method:Delegate *
args:Object[] -> IAsyncResult
function BeginInvokeOnUIThread(
method : Delegate,
... args : Object[]
) : IAsyncResult
參數
- method
型別:System.Delegate
方法的委派,採用和 args 參數中包含者相同的數字和型別的參數。
- args
型別:array<System.Object[]
做為引數傳遞至指定方法的物件陣列。如果方法沒有引數,這個參數可能是 nullNull 參照 (即 Visual Basic 中的 Nothing)。
傳回值
型別:System.IAsyncResult
表示這個運算結果的 IAsyncResult 執行個體。
備註
這個方法會在背景執行緒運作並定期需要告知更新 UI 執行緒對作業的多執行緒案例中很有用。這類情節中引發由單一執行緒的管理 COM 元件在機器碼中的事件。
當呼叫這個方法時,它會通知訊息至 UI 執行緒中啟動視窗訊息佇列,在處理呼叫指定的方法。這個方法是非同步的,則呼叫的執行緒會立即傳回,一旦公佈訊息。傳回的執行個體 IAsyncResult 可由背景執行緒來決定處理在 UI 執行緒上的這個訊息何時完成。
範例
下列程式碼示範這個方法的用法說明無法從背景執行緒存取的原生 Visual Studio 服務。
using System;
using System.Threading;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Shell.Interop;
public class DdexHostSvcExample3
{
public static void UpdateUI(IVsDataHostService hostService)
{
if (hostService.UIThread == Thread.CurrentThread)
{
// Called on UI thread, directly call method
ActuallyUpdateUI(hostService);
}
else
{
// Called from background thread, invoke on UI thread
hostService.InvokeOnUIThread(
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。