How to make WPF application running in background

Deok Jong Moon 125 Reputation points
2023-06-30T01:02:05.5533333+00:00

Hi there,

I'm fairly a beginner in C# and .NET, and basically the ultimate goal I'd like to achieve is to make a Windows application that has

  1. running in background,
  2. automatically starts when device is booted up,
  3. but has UI, which could show up by clicking on it in the system tray.

For this purpose, I've seen that I could use WPF solution and add background running component in it. But, almost all the articles dealing with the topic is written long time ago, and even when I try to a class such as System.Windows.Forms.NotifyIcon, it won't show up in my WPF solution's Nuget package manager or anywhere in it.

I'm okay with any other better and easier solution to achieve my goal.

Please give me some advice on it.

Kind Regards,

DJ Moon

Developer technologies Windows Presentation Foundation
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2023-07-01T14:22:13.5633333+00:00
    1. running in background,
    2. automatically starts when device is booted up,
    3. but has UI, which could show up by clicking on it in the system tray.

    In C#, you can just use P/Invoke for the System Tray

    I had uploaded a sample in WinUI 3 (https://github.com/castorix/WinUI3_NotifyIcon)

    (function TrayMessage in NotifyIcon.cs)

    You can do it in WPF, Winforms, WinUI 3 (you simply hide/show the main window as I did when I minimize/restore it)

    To launch the program at Startup, you can write the path+exe in one of the registry keys ,like

    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.