如何使用计时器在用户指定的时间内提醒我的事件? [英] How to use timers to remind my events on a time specified by user?
本文介绍了如何使用计时器在用户指定的时间内提醒我的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
完成提醒应用程序并完成所有插入/更新/删除事件,我现在需要的是在添加事件(已保存的表)时弹出用户指定的特定tym上的消息。请帮助我
Done a reminder application & i am done with all insert/update/delete events, what i need now is to popup messages on a particular tym specified by user while adding event(saved table). Please help me
推荐答案
Abdul,我认为您需要做的是创建一个每60秒触发一次的计时器。当它触发时,检查用户的提醒以查看是否有任何结果,然后显示一个包含该信息的对话框。
Abdul, I think that what you need to do is create a timer that fires every 60 seconds. When it fires, check the user's reminders to see if anything is due and then display a dialog box with the information.
这是一些演示计时器的简单代码。
Here is some simple code to demonstrate a timer.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TimerExample
{
public partial class Form1 : Form
{
private List<tuple><datetime,>> appointmentList;
private Timer timer;
public Form1()
{
InitializeComponent();
lblMessage.Text = "";
}
private void btnStart_Click(object sender, EventArgs e)
{
// Create a list of test calendar items
CreateCalendarItems();
// Create the timer and start it
CreateTimer();
lblMessage.Text = "Timer Started";
SetTime();
}
private void CreateCalendarItems()
{
appointmentList = new List<tuple><datetime,>>();
// Add 3 example appointments to the list
appointmentList.Add(new Tuple<datetime,string>(DateTime.Now.AddMinutes(1), "Budget meeting"));
appointmentList.Add(new Tuple<datetime,string>(DateTime.Now.AddMinutes(2), "Marketing meeting"));
appointmentList.Add(new Tuple<datetime,string>(DateTime.Now.AddMinutes(3), "Project Review"));
}
private void SetTime()
{
txtTime.Text = DateTime.Now.ToLocalTime().ToShortTimeString();
}
private void CreateTimer()
{
timer = new Timer();
timer.Interval = 10000; // 10k milliseconds equal 10 seconds
timer.Tick += timer_Tick;
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
SetTime();
var appointments = appointmentList.Where(a => a.Item1 <= DateTime.Now);
if (appointments.Count() > 0)
{
string msg = "The following appointments are due:\n\r\n\r";
// For this simple demo we are displaying all appointments that are due at or before the current time
foreach (var item in appointments)
msg += String.Format("{0} - {1}\n\r\n\r", item.Item2, item.Item1);
MessageBox.Show(msg);
}
}
}
}</tuple></tuple>
这篇关于如何使用计时器在用户指定的时间内提醒我的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文