IVsDataHostService.UIThread Property
Gets the main (UI) thread running in the Visual Studio process.
Namespace: Microsoft.VisualStudio.Data.Core
Assembly: Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)
Syntax
'Declaration
ReadOnly Property UIThread As Thread
'Usage
Dim instance As IVsDataHostService
Dim value As Thread
value = instance.UIThread
Thread UIThread { get; }
property Thread^ UIThread {
Thread^ get ();
}
function get UIThread () : Thread
Property Value
Type: System.Threading.Thread
The main (UI) thread running in the Visual Studio process.
Remarks
This property is useful for determining whether code is currently running on the main thread of the Visual Studio process. This is often useful surrounding calls to the InvokeOnUIThread or BeginInvokeOnUIThread methods to avoid the overhead of a dynamic delegate invoke.
Examples
The following code demonstrates a typical use of the UIThread property to determine whether a method that must run on the UI thread can be called directly or must be dynamically invoked to marshal the call between threads.
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.