I have integrated a small to-do list in my WinForms application, where-in user can add tasks and set alarm for it. Is it possible to run timer (or alarm clock counter) in background, even if application is closed. I am using the AlarmClass written as answer here. The aim is only to show a MessageBox when the alarm time is reached and nothing else to do with the application. Also multiple alarm setting should be possible.
I am sorry if my question is not elaborated, coz I dont know wat other details I must include. But ready to reply your questions.
Thanks in advance.
Edit: Any comments on this link?
Short answer
No. If your application is shut down, there's no good way.
Long answer
Yes if you resort to clever hackery. You could:
Run your app in the system tray / background when the 'X' button is clicked
Run a scheduled task which launches your app in "alarm-checking" mode every N minutes
Write a windows service which launches your app for alarm events
I'm not sure, but can't you create a Windows application which only shows up in the Systemtray. Add the required keys to the registry to make sure it will automatically start when windows starts.
Otherwise you can split it up into two separate applications;
- Windows Application to manage the alert
- Windows Service to do the check in the background
Related
I am building a WP7 app. I want to reset my app data settings at a given time. I have tried resetting by comparing the hour of the given time and "DateTime.Now.Hour" when the Main Page loads(i.e. when I open the app at the given time). But if I open the app after the given time, it doesn't reset at all. So, I want to know if there is any way to solve this. I haven't used Background Worker before but I think it can help. Can somebody suggest me a way out of it?.
Thanks in advance
You cannot run apps permanently in the background on Windows Phone. When your app launches or is activated you should check if the delete time has passed (DateTime.Now > deleteTime).
You could consider using a background agent that can run every 30 mins, but beware the limitations especially on 256MB devices.
For practical purposes but also as a learning exercise, I am wanting to create notification application to remind me of friend's Birthdays. I would like the application to be running in the background so that it can check the current date against user configured reminders. If a reminder is due then the user is displayed a simple Window that will allow them to snooze or dismiss the notification. I want the application to have user specific notifications (i.e. User A's notifications are not seen when User B is logged in).
Option 1 - Application launched upon Windows startup:
I thought about keeping it simple by checking when to display notifications only when the application starts up. I would then put a shortcut in the Windows Startup folder. However, this probably wouldn't work if the PC is put to sleep and resumed each day.
Option 2 - Application constantly running in background:
I then thought about making the application so it minimises to an icon in the System Tray and thus would constantly be running in the background. It would then periodically check when to display notifications.
Option 3 - Using Windows Service with application:
I then thought about using a Windows Service to do the periodic checks as to when to display notifications. Obviously, a Windows Service cannot display UI notifications so it would need to use some other mechanism for notification (e.g. sending an email). An application could then be used to configure settings that the service uses.
Are there any other options that I have not considered which would work better. I'm currently inclined to go with option 2 for my first implementation but could look to move to a better solution afterwards.
TIA
Your option 2 is the optimal one since you are aimed to distinct users and their reminders - your application runs in the context of a particular user, you already know which remainders need to be shown. Of course, you could go for the third option but this way is really need more time to code and the code itself would be more complex. I would go for the second option. As your applications is WinForms, for the periodical checks I would recommend you to use System.Windows.Forms.Timer class.
By the way, showing an icon in the tray notification area does not make your application "run in the background", it is just a convenient way to show your application is up and running.
Basically, I have an application that runs every 15 minutes. I would like this Console application to remain hidden and not for example minimise/disturb full screen applications.
What would be the best way to accomplish this, it can't be a service though. I'm writing the console application in C#.
Thanks.
To run an application every 15 minutes use a scheduled task. The very simple way to avoid any window being shown is to make this a normal GUI app rather than a console app, but arrange that you do not show any windows in your GUI app.
like david said if you make it a gui program but never load any windows it will run in the background with nothing ever popping up or showing or anything.. another option would be to have your application run continuously and have it do something every 15 minutes...
One option would be to have the scheduled task run as a different user, Network Service maybe, depends on your needs. This will force it to run under the specificed users context and will not show up on other logged in users screens.
You don't need to do anything. A console application is invisible and doesn't interact with other windows. The only way to even know it's there is through Task Manager or something similar.
I would like to set up a persistent state for my application. Let me explain.
The startup time is kinda long (mostly due to many database requests to a remote server, which take 5 - 10 seconds, and even more since my users usually have too much applications running...) and I'd like to set up a way to hide & show my application when needed.
What I am doing now is to only reduce app to tray when user clicks on the red cross. (The application really exits only when a user chooses File -> Exit).
All users are launching an installer which is checking the version installed, then the version available online, and update the app if needed before launching it.
Now, I'd like it to first check on the process monitor (the one found in Task Manager, Processes tab), and if a process is already running for the application, it'll just show the window again. Otherwise, if no process is running, we can process the classic-check-for-update-then-launch steps.
This would especially remove a lot of stupid customer requests I regularly have ("hey, your application takes too long to load, so I clicked on it again 5 times and it launched 6 instances!!!!" :/ ) and therefore save me a lot of useless time spent asking them to stop launching 50 instances of the same application cause it won't make it any faster...
So my main question is: how to perform such a trick in C#/WPF?
For now, my minimization process is kinda simple (even though maybe too simple): I just hide the window & the task bar entry. Now I don't know how to show it back from my installer
Any ideas?
Your customers' requests can never be stupid - they pay you money.
To bring window to front - create system wide mutex and check its presence on application startup. If it's there - use interprocess communication mechanisms to send message to that other instance to bring its main window to front (a window message or named pipe - both are fine). Here is an example (make sure to check related answers too).
And by any means show splash screen as soon as you can to prevent relaunching application again and again. If it does not appear in 1-2 seconds (2 is too long) it's bad. Responsiveness of your application makes feeling like it works faster.
Is it something like this you're looking for?
foreach (var p in Process.GetProcesses())
{
if (p.ProcessName.Contains("myProcess"))
{
//process is already running
}
}
Or, with LINQ:
if (Process.GetProcesses().Where(p => p.ProcessName.Contains("myProcess")).Any())
{
//process is already running
}
If the users complain about startup times, maybe consider checking the version on exit, instead of startup.
I have answered a very similar question yesterday. The only bit that's missing there is how to hide and show the window: use Window.Visibility, set it to Visibility.Hidden to hide the window and to Visibility.Visible to show it again.
I'm creating a WP7 app that needs to continue running when the user is not using the phone - ideally the user sets it going, locks the phone and carries on with their life.
Is this possible?
I know it is possible to disable the lock screen, so if the user were to just leave the phone on a table it would be fine and carry on running. The problem is when they put it in their pocket - buttons will get pressed such at the windows/home button, and if this happens then the app is tombstoned straight away.
Any ideas if this is possible? Either somehow locking the phone without tombstoning the app, or implementing a sort of custom lock screen and handling the events for all the hardware buttons including the windows/home button?
Any suggestions will be appreciated.
Just as you figured out:
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
No need to ask user for permission anymore (since the original 6.3.1 "Configurable Functionality" was dropped). However, there are other Marketplace certification requirements to consider, see section 6.3: http://go.microsoft.com/fwlink/?LinkID=183220
I think I've done it again - asking questions too soon.
I believe the following setting:
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
will enable the application to run under a lock screen.