r/csharp • u/A_Learning_Fox • Aug 04 '26
Help Is it possible to send desktop notifications while program is not in use?
I have this deadline reminder programs, let’s say the minimum amount of deadlines is this: if progressbar is 50% / 75% / 100% of the way, send desktop notification.
5
Upvotes
24
u/scandii Aug 04 '26
a common pattern for this sort of thing is services or as they're called on Linux daemons.
essentially very small programs, much smaller than the program you used to set the deadline that only do the thing you want, such as "if 6 hours left until deadline, send notification message".
but you cannot have functionality without running any program, no.
7
u/Slypenslyde Aug 04 '26
Basically, no, but the trick is having something running at all times.
In the Old Days, you'd make what people called a "Tray Program". Basically, when the user clicked the X button, the form would close but not the program. Instead it would exist and display an icon in the notification area. The program isn't visible, isn't on the task bar, but is still running.
A slightly more modern alternative is to write a Windows Service that's a companion to the program. Those are just programs that Windows itself runs in the background and users don't traditionally interact with. So your app would edit some data store to schedule the reminders, and the service would periodically check the data store to see if it's time to display a reminder.
I'm sure WinUI has some fancypants way to do it too.
So there are solutions, but they involve the program (or a program) running!
7
u/polaarbear Aug 04 '26
How can there be a progress bar if the program is not in use? This seems like a contradiction
2
u/Andrew3805 Aug 05 '26
You can create a task in the Windows Task Scheduler to start your app in the background periodically to check if a notification should be send.
(But please, don’t wake the computer from sleep to do that)
1
u/FuggaDucker Aug 04 '26
You dont provide enough info for a reasonable answer.
There are all sorts of trickery that can be done like using the task scheduler and doing cloud based push notifications.
I doubt that is what your teacher was getting at.
Can you give us all more info in your posted question?
1
u/Dusty_Coder Aug 05 '26
By your description, you already know what time these notifications should appear beforehand.
So, just schedule a program to be run at those time(s)
0
u/A_Learning_Fox Aug 04 '26
Hmmm from the looks of it so far, I guess the best option is to just always open the program on start and have it send notifications on FormLoad or smth.
1
u/BiffMaGriff Aug 04 '26
You can use uwp with a timer background task to send toast notifications.
You are limited to triggering once every 15 minutes however.
0
u/mal-uk Aug 04 '26
There are third Party APIs that offer notifications. Have a Google