【问题标题】:Wpf Application Does not start at startup but run manually?Wpf应用程序在启动时不启动而是手动运行?
【发布时间】:2017-03-29 13:28:48
【问题描述】:

我在 WPF 中创建了一个应用程序,它只是轮询应用程序。现在我想在 Windows 启动时启动该应用程序(用户登录后)。我还使用 Wix 工具集创建了一个安装程序包,它将注册表项添加到 Software\Microsoft\Windows\CurrentVersion\Run。程序实际上尝试运行但没有给出错误。我能够从 Windows Event Viewer 中得到错误,但我无法理解这个错误是在哪里产生的。

堆栈跟踪:

Application: icBlync.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
   at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare)
   at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCacheOption, System.Guid ByRef, Boolean ByRef, System.IO.Stream ByRef, System.IO.UnmanagedMemoryStream ByRef, Microsoft.Win32.SafeHandles.SafeFileHandle ByRef)
   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(System.Uri, System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCreateOptions, System.Windows.Media.Imaging.BitmapCacheOption, System.Net.Cache.RequestCachePolicy, Boolean)
   at System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(System.Uri, System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCreateOptions, System.Windows.Media.Imaging.BitmapCacheOption, System.Net.Cache.RequestCachePolicy)
   at System.Windows.Media.Imaging.BitmapFrame.Create(System.Uri, System.Net.Cache.RequestCachePolicy)
   at System.Windows.Media.Imaging.BitmapFrame.Create(System.Uri)
   at icBlync.Windows.SettingWindow..ctor()
   at icBlync.App..ctor()
   at icBlync.App.Main()

请帮忙。

【问题讨论】:

  • 好吧,在我看来,应用程序 (icBlync.exe) 已启动。当尝试访问某个文件或目录(读/写)时,它会中断,因为该目录尚未创建。您是否有任何执行文件系统操作的代码,或者您确定您的安装程序创建了所有必需的路径?
  • 请注意,您的工作目录可能不一样,因此如果您使用相对路径,可能会出现问题。
  • 如果我手动运行应用程序,它可以完美运行。自动启动时出现此错误。
  • this answer 显示了您可能需要的位。
  • 感谢@Damien_The_Unbeliever 帮助我。

标签: c# .net wpf windows


【解决方案1】:

当应用程序从启动时启动时,工作目录不是安装目录。因此,当应用尝试加载图标时,它会给出 System.IO.DirectoryNotFoundException

我刚刚将工作目录更改为已安装目录,使用:

Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2013-03-10
    • 2013-08-09
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多