my app is not starting on windows start up WPF

0

Hello
i add the code below to start the app on windows start up.

        try
        {
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            Assembly curAssembly = Assembly.GetExecutingAssembly();
            key.SetValue(curAssembly.GetName().Name, curAssembly.Location );
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

it is add the registry string to run folder, i restart my pc to test it, put the app was not running on start, i lunch the visual studio and try to debug it again but i got this output

Build started...
1>------ Build started: Project: Notes, Configuration: Debug Any CPU ------
1>D:\installed programs\Microsoft Visual Studio 2019\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4394,5): warning MSB3026: Could not copy "obj\Debug\Notes.exe" to "bin\Debug\Notes.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\Notes.exe' because it is being used by another process. The file is locked by: "Notes.exe (6212)"
.
.
.
1>D:\installed programs\Microsoft Visual Studio 2019\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4394,5): error MSB3021: Unable to copy file "obj\Debug\Notes.exe" to "bin\Debug\Notes.exe". The process cannot access the file 'bin\Debug\Notes.exe' because it is being used by another process. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i think it is mean the app is running or something like that, and visual studio cant run it again
but there is no app, maybe it is running in background,
windows event says this

Faulting module name: KERNELBASE.dll, version: 10.0.18362.1316, time stamp: 0x7a6bfa05
Exception code: 0xe0434352
Fault offset: 0x001146d2
Faulting process id: 0x1b38
Faulting application start time: 0x01d6ea60ff8af3d0
Faulting application path: D:\projects\windows-projects\real projects\C#\WPF-apps\Notes\bin\Debug\Notes.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: fd5efe22-ff65-45e7-9c98-0b4f75c572cf
Faulting package full name: 
Faulting package-relative application ID:



> and this one:  
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.Drawing.Icon..ctor(System.String, Int32, Int32)
   at System.Drawing.Icon..ctor(System.String)
   at Notes.MainWindow.setSystemTrayIcon()
   at Notes.MainWindow..ctor()

Exception Info: System.Windows.Markup.XamlParseException
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
   at Notes.App.Main()`
c#
wpf
window
startup
asked on Stack Overflow Jan 13, 2021 by Jafar Rezazadeh • edited Jan 15, 2021 by Jafar Rezazadeh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0