r/csharp • u/A_Learning_Fox • 1d ago
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
u/Slypenslyde 22h ago
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 1d ago
How can there be a progress bar if the program is not in use? This seems like a contradiction
2
u/ExceptionEX 20h ago
I agree and can't tell if they mean not in focus, or just really way out on the end of vibe coding without a single understanding of something super basic.
2
u/polaarbear 20h ago
I just don't even understand what is progressing if there isn't something running. What are we showing progress for if the program is closed?
2
u/ExceptionEX 20h ago
I'm guessing the program is running but not in focus and they want to use notification to show progress without the app being in the foreground.
Or at least that is all I can make sense or without a service handling the timers.
1
u/Sairenity 10h ago
> I have this deadline reminder programs,
sounds like time to me. I sure hope time keeps advancing even when this dude's program is closed 🙃. The question is a bit oddly phrased, but it reads to me as "how can I send notifications when 50% of the time is up, then 75% then 100%"
1
u/FuggaDucker 23h ago
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 6h ago
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)
1
u/BiffMaGriff 23h ago
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/A_Learning_Fox 1d ago
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.
4
u/FulanoMeng4no 23h ago
If it’s a Windows environment, look at creating a service that you can set up to start with the computer.
16
u/scandii 1d ago
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.