Home > Software design >  Scheduled Notifications in Windows 10 VB.Net
Scheduled Notifications in Windows 10 VB.Net

Time:10-22

I am working on a project where the user sets a reminder with information, date and time for when a notification should pop up and the notification should be clickable and open another form with the reminder information on it. So far I can set the reminder but it pops up as soon as the remind button in clicked, my notification looks a standard windows 10 notification, I just want the notification to be scheduled for a certain date and time. The information including date and time is saved into an Access Database. I am using VB.Net.

Kind Regards

CodePudding user response:

You need to use a Timer and to avoid the constant reading of the database you may use something very simple as a DateTimePicker or a TextBox. In this example I'll use a Texbox.

So, insert a TextBox1 in your form and had the value of the first date/time (read from your database just once). The Textbox1 text should be something like "2021-10-21 15:00" (don't put the seconds and don't forget to have a space between date and time)

TextBox1.Text="2021-10-21 15:00" ' read this data from your database 

Then you need to insert a Timer in your form and add this values:

Timer1.Interval = 60000 ' 1 minute
Timer1.Enabled = True

For the last you need to double click the Timer1 and write this code:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If TextBox1.Text = Now.ToString("yyyy-MM-dd HH:mm") Then 
       ' At this moment you should read the next date/time and put that in TextBox1
       MsgBox("Show the popup notification") 
    End If
End Sub

CodePudding user response:

Since you are using DB connections, ill assume you are familiar with multi threading.

RULE 1. The easiest way to do this is for your application to keep track of (in RAM) the next notification. Any time you add a new one through your app it will both insert it into the DB as well as check to see if it is going to elapse before the current one in RAM. When the one in RAM expires it grabs the next one from the DB. All that to say, you find a way to ensure that the next one to elapse is kept in RAM at any given time.

RULE 2. Then, when a notification is 'saved' in RAM, compare the time when the notification should be displayed - current time, this will give you how long until the notification should de shown and set a timer for that amount of time.

RULE 3. When the timer has elapsed display the notification for the one that is in RAM (Per rule 1 this is the one that just elapsed). And iterate the DB to find the next one to expire. Rinse and repeat. (Note, youll need to handle edge cases for when the first one is intered as there will not be any to compare to, and for when the last one is notified as there will not be any notifications left to store in RAM)

Tada, sorry i dont have code samples. But that is how i have solved this very issue numerous times. It works quite nicely.

  • Related