我有一个在Windows 7计算机上运行的C#.NET WPF(MVVM Lite)应用程序。 它适用于.NET 4.5。
虽然客户端上安装了.NET 4.5.2,但它应该运行。 客户端更新到.NET 4.7并卸载.NET 4.5.2(!)后,应用程序将在启动时挂起:
Frameworkversion:v4.0.30319 Beschreibung:D过程终止 由未处理的例外。异常信息: System.Runtime.InteropServices.COMException bei MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(的System.Guid ByRef,System.Object,Int32,System.Guid ByRef)bei MS.Win32.Penimc.UnsafeNativeMethods.CreatePimcManager()bei MS.Win32.Penimc.UnsafeNativeMethods..cctor()
异常信息:System.TypeInitializationException bei MS.Win32.Penimc.UnsafeNativeMethods.CreateResetEvent(IntPtr ByRef)bei System.Windows.Input.PenThreadWorker..ctor()bei System.Windows.Input.PenThreadPool.GetPenThreadForPenContextHelper(System.Windows.Input.PenContext) 北 System.Windows.Input.PenThreadPool.GetPenThreadForPenContext(System.Windows.Input.PenContext) 北 System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTabletsImpl() 北 System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTablets() bei System.Windows.Input.StylusWisp.WispTabletDeviceCollection..ctor() bei System.Windows.Input.StylusWisp.WispLogic.get_WispTabletDevices() 北 System.Windows.Input.StylusWisp.WispLogic.RegisterHwndForInput(System.Windows.Input.InputManager, System.Windows.PresentationSource)bei System.Windows.Interop.HwndStylusInputProvider..ctor(System.Windows.Interop.HwndSource) 北 System.Windows.Interop.HwndSource.Initialize(System.Windows.Interop.HwndSourceParameters) bei System.Windows.Window.CreateSourceWindow(布尔)bei System.Windows.Window.CreateSourceWindowDuringShow()bei System.Windows.Window.SafeCreateWindowDuringShow()bei System.Windows.Window.ShowHelper(System.Object)bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)bei System.Windows.Threading.DispatcherOperation.InvokeImpl()bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object的) 北 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object,Boolean)bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback,System.Object)bei MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback,System.Object)bei System.Windows.Threading.DispatcherOperation.Invoke()bei System.Windows.Threading.Dispatcher.ProcessQueue()bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr, IntPtr,Boolean ByRef)bei MS.Win32.HwndWrapper.WndProc(IntPtr,Int32, IntPtr,IntPtr,Boolean ByRef)bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object,Int32)bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object的, System.Delegate,System.Object,Int32,System.Delegate)bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan,System.Delegate,System.Object,Int32)bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 北 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)bei System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 北 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) bei System.Windows.Application.RunDispatcher(System.Object)bei System.Windows.Application.RunInternal(System.Windows.Window)bei System.Windows.Application.Run(System.Windows.Window)bei ApplicationName.App.Main()
App.xaml.cs已修改:
public partial class App : Application, ISingleInstanceApp
{
private static string Unique = "Test_xx";
[STAThread]
public static void Main()
{
for (int i = 1; i < Environment.GetCommandLineArgs().Length; i++)
Unique += Environment.GetCommandLineArgs()[i];
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
var application = new App();
application.InitializeComponent();
application.Run();
// Allow single instance code to perform cleanup operations
SingleInstance<App>.Cleanup();
}
}
public bool SignalExternalCommandLineArgs(IList<string> args)
{
if(args.Count < 3 || args[2].ToUpper() != "AUTOSTART")
MessageBox.Show("Program already runs!","Error!",MessageBoxButton.OK,MessageBoxImage.Warning);
Current.MainWindow.WindowState = WindowState.Maximized;
return true;
}
protected override void OnStartup(StartupEventArgs e)
{
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
}
有什么想法吗?