我正在测试需要提升权限的C#WPF程序,如果我以管理员身份登录但没有任何延迟加载,但是如果以标准用户身份登录(99%的时间),那么在用户界面出现之前会有约30秒的延迟。具有提升特权的应用程序加载缓慢
在C#控制台应用程序和c#Winforms应用程序中使用相同的高程代码,加载时没有延迟,所以我知道代码有效。 那么,任何人都可以向我解释为什么有一个与WPF相关的延迟;有没有解决方法?
下面是从app.xaml.cs代码(该项目的剩余部分由VS2010作为genereated)
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Security.Principal;
using System.Diagnostics;
using System.Reflection;
using System.ComponentModel;
using MyNewServiceLib;
using System.Runtime.InteropServices;
namespace WhySoSlow
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!IsAdmin())
{
StartAsAdmin(e);
Application.Current.Shutdown();
}
else
{
MainWindow = new MainWindow();
MainWindow.SizeToContent = SizeToContent.WidthAndHeight;
MainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
MainWindow.Show();
}
}
bool IsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal p = new WindowsPrincipal(id);
return p.IsInRole(WindowsBuiltInRole.Administrator);
}
private void StartAsAdmin(StartupEventArgs e)
{
string[] args = e.Args;
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
Uri uri = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);
startInfo.FileName = uri.LocalPath;
startInfo.Arguments = String.Join(" ", args);
startInfo.Verb = "runas";
Process p = Process.Start(startInfo);
}
catch (Win32Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
}
更多信息 古怪,如果我从一个命令提示符运行启动程序在NT Authority \ System下,启动UI没有任何延迟。在一次成功的开始之后,每一次进一步的开始,无论何时提示,都是标准的用户提示,以管理员身份运行,程序立即启动;直到我退出会议。 再次登录到新的(标准用户)会话后,在显示UI之前,所有尝试启动程序的结果都是30秒延迟。 我只能认为这是微软的一种UAC bodge,这阻碍了wpf的启动。
这将有助于如果我们能看到的代码 – CJK
哎呀,对不起“布特说,现在又增加了。 –
欢迎来到Stack Overflow!我编辑过你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –