显示定期通知 [英] Display a Periodic Notification

查看:70
本文介绍了显示定期通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想在应用程序中定期显示通知(例如,每1小时显示一次),因为我试图在VS中使用计时器工具,但它不接受长整数.
有任何通知工具可以显示我的消息吗?

我的意思是通知:对于wpf应用程序,这样的小窗口会向用户显示 WPF NotifyIcon [ ^ ]
我想要用于c#应用程序.

Hello,
I want to display notifications in my application in a periodic time ( each 1 hour for example) how can I do that , because I tried to use the timer tool in VS but it doesn''t accept long integer.
Is there any notification tool to display my message?

I meen by notification : a small window appears to the user like this one for wpf applications WPF NotifyIcon[^]
I want it for c# application.

推荐答案

使用计时器.您不需要很长,整数就足够了.间隔将为3600000(1000 * 60 * 60).

如果由于某些原因您确实不想使用计时器,则可以创建一个新线程并休眠任意长时间(System.Threading.Thread.Sleep),然后执行所需的任何操作.一旦该线程完成了操作(例如,通知),该线程便会创建一个执行相同操作的新线程.
Use a timer. You don''t need a long, an integer will suffice. The interval would be 3600000 (1000 * 60 * 60).

If you really don''t want to use the timer for some reason, you can create a new thread and sleep for however long you want (System.Threading.Thread.Sleep), then perform whatever action you want. Once that thread finished doing the action (e.g., a notification), that thread would then create a new thread that does the same thing.


取决于通知"的含义.您可以只使用MessageBox.ShowDialog()在消息框中向用户显示字符串.或者,您可以使用所需的任何通知文本来更新控件上的标签.或者,您可以向用户发送电子邮件.一切都取决于通知"的含义.根据实现方式(使用计时器或线程),您可能必须使用Invoke通知用户.调用是每个Windows窗体(以及我相信的每个控件)上的一种方法.这样可以防止您从不是在其创建线程的线程中"访问控件的错误.如果您想进一步了解Google,请点击"Invoke"和"InvokeRequired".

顺便说一句,不要发布问题作为答案.相反,请使用可能需要的其他详细信息来修改原始问题.
Depends on what you mean by "notification". You could just use MessageBox.ShowDialog() to display a string in a message box to the user. Or you could update a label on your control with whatever notification text you want. Or you could send out an email to a user. All depends on what you mean by "notification". Depending on how you implement it (with a timer or with a thread), you may have to use Invoke to notify the user. Invoke is a method on every Windows Form (and on every Control I believe). It prevents the error where you access a control "from a thread other than the one it was created on." Google "Invoke" and "InvokeRequired" if you want to know more about that.

By the way, don''t post questions as an answer. Instead, modify your original question with any additional details you might have.


表格外观效果和通知窗口


这篇关于显示定期通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆