How to set an Alarm or Reminder events in Windows 8? - c#

Do we have a functionality in Windows 8 where I can set an Alarm or a Reminder (with recurrence!!) and forget about it (and the OS will do the rest)? Or do I need to create a background task to do the work?
It is not hard to schedule one event but I would not want to schedule a whole set of recurrence events.
The calendar is already doing it, can I tie into this mechanism?

You can use Scheduled Notifications but there's a limit of 4096 of those, so the recommendation for a recurring task would be to use a MaintenanceTrigger. A couple of things to be aware of:
A maintenance trigger will NOT fire if on battery power, but the
notifications are buffered so when you're plugged in again you'll
receive them.
There's up to a 15 minute window from the freshnessTime in terms
of the actual notification being triggered, so keep that in mind in
terms of scheduling. For instance, if you set a notification to
occur at noon, it might not hit until 12:14:59.

Related

UWP timer based on system time

I am looking for a way to have an "alarm" type timer that throws an event at a specific system time. Is there a way to do this with UWP apps? I need my application to be able to enter "day mode" at a certain time in the day. Currently, I am using a System.Timers.Timer(), but if the computer goes into sleep mode in the middle of the timer running, it does not count sleep-mode time as part of the timed event. Is there a way to have an alarm type event that is based off of system time as opposed to "timed" time?
Is there a way to have an alarm type event that is based off of system time as opposed to "timed" time?
I have to say that the answer is no. There is no such way that could make an alarm still function in sleep mode. Even the system build-in Alarm app won't work in sleep mode.

Windows 8 BackgroundTasks(TimeTrigger)?

I am new to windows 8. I'd like to remind the user about a task stored in my application.
Scheduled notification allows me to raise a toast and update the app's tile to remind the user. But it doesn't support recurrence (repeat feature). So I want to use a background task with time trigger. The documentation says the app should be present on the lock screen.
This is confusing, what exactly does this mean? When will the background task trigger? How can I use it so that it supports recurrence and I can notify the user. Any sample to this would be appreciated.
Time trigger tasks are only available to apps on the lock screen. There is a maintenance task, however, which is available to all apps. Instead of requiring placement on the lock screen, maintenance tasks only run when the device is plugged in to AC power.
See How to use the maintenance trigger.

How can I get computer status in c#

I want to create something like a client in c#.
But I do not know that how I can learn computer status like sleep mode, off, logged in or logged out.
Also, I need to get the warning if the user haven't used the computer for 10 minutes.
You can find information about currently logged user and how to hook the Locked/Unlocked events in this thread.
There are some other different approaches you might try:
You can use the System.Diagnostics and get the process list via Processes.GetProcesses(). Just keep an eye on the Idle process -- if it runs for more than 50% CPU longer than 10 mins the user seems to be idling too.
You can use Performance Counters to monitor the activity taking place on the computer and make certain decisions.
You can also use the WMI service with similar purposes.
Partial answer:
User activity/inactivity can be monitored using hooks. Start a timer with a 10-minute interval. Whenever you detect a keyboard/mouse message, restart it. If the timer event happens, than you detected 10 minutes of inactivity.

Best way to handle Timers?

I wanted to create something similar to the way anti-virus programs sit in the Tray and can re-do an event (e.g. a scan) on an interval. I have a program that exports data from our SQL server and the user sets up a queue of what they wanted exported.
I was thinking about using System.Windows.NotifyIcon
http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
and
System.Timer
http://msdn.microsoft.com/en-us/library/system.timers.timer%28v=vs.71%29.aspx
Let's say the user has it set to repeat every X hours or "Every Day" or "Every Wednesday at 5:00". Should I just create a tray icon and
this.Hide();
and setup a timer that ticks and compares the time when the timer was started against whatever criteria the user set? Or, is this an inefficient and memory wasting way to do it? Is there any way to "schedule" an event to fire at a certain time and handle it that way?
You can use Windows scheduled tasks.
There is a library called Task Scheduler Managed Wrapper that can be used to set up tasks from c#.

Windows Mobile - detecting when power off button is pressed

Is there an easy way to get notified when user presses Power Off button on it's Windows Mobile device? Using C# of course.
Thanks!
When the power button is pressed, the power manager will send out a notification of a state change. You can request that the PM send you a notification by calling RequestPowerNotifications You have to send in a handle to a point-to-point messgae queue (managed version here) that will get the notification.
For thos who don't want to write all of the glue to make this work, all of this is already pre-done for you in the SDF's PowerManagement class.
Also be forewarned that just becasue you request the notification does not mean that your app will get the notification before the state change occurs. For example on pwer down it's pretty common that an app won't see the notification, and almost certain that even if you do see it you won't have time to execute anything before suspend actually occurs. Typically your handler will run when the device resumes (followed by any handler for the resume state).
The power manager doesn't wait for you, it simply broadcasts a message. You cannot use this to run code before a shutdown.
I just place CreateMsgQueue() into the XIP RPM binaries, without need for source code or OEM help. you need to use a hex editor and a few tools from XDA forums.
<DllImport("coredll.dll", SetLastError:=True)> _
Public Shared Function CreateMsgQueue(ByVal lpszName As String, ByVal lpOptions As MsgQueueOptions) As IntPtr
End Function
also you should just create a simple driver for blocking the power down event, your driver is allowed to hold up the power down process in the PowerDown device Event. that way you get a guaranteed event that you can set the flag and stop your background running process, and store any variables, and then restore them on ther PowerUp event, which is also a standard evc++ event for winCE device driver. Pretty simple really. there is 100s of demo source code on the internet for this, I've seen it on 100s of sites.
Unfortunately, on the Windows CE 6 device i am using, CreateMsgQueue does not exist in CoreDll. Any other suggestions?
The only thing i can think of is continually checking Environment.TickCount against the device's real time clock. If time has moved forward but not the tick count, then presumably the device was sleeping.
Dont like this solution because it will get tricked if the time jumps due to a failure in the device's real time clock

Categories

Resources