本文整理汇总了C#中System.IServiceProvider.GetUIThread方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetUIThread方法的具体用法?C# IServiceProvider.GetUIThread怎么用?C# IServiceProvider.GetUIThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.GetUIThread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowMessageBox
/// <summary>
/// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
/// uses a private interface that can't be mocked AND goes to the global service provider.
/// </summary>
public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton) {
IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
if (uiShell == null) {
throw new InvalidOperationException();
}
Guid emptyGuid = Guid.Empty;
int result = 0;
serviceProvider.GetUIThread().Invoke(() => {
ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
0,
ref emptyGuid,
title,
message,
null,
0,
msgButton,
defaultButton,
icon,
0,
out result));
});
return result;
}