设置软件的时间限制 [英] set time limit for a software

查看:120
本文介绍了设置软件的时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

软件应只能在上午8点至晚上10点之间运行.如何在我的系统中实现此时间限制.

A software should be able to run only between 8am and 10 pm. How can I implement this time limit to my system.

推荐答案

使用DateTime.现在,您将获得当前时间:
Using DateTime.Now will give you the current time:
DateTime now = DateTime.Now;

然后,您可以使用Hour属性来检查您是否在允许的时间内:

You can then use the Hour property to check if you are within permitted hours:

if ((now.Hour >= 8) && (now.Hour <= 20))
   {
   // OK to run
   ...
   }

在您的应用上设置一个计时器,该计时器每分钟触发一次(例如),并检查其中的时间.

更改系统时钟可以轻松解决此问题,但是您可以通过从互联网供应商那里获取时间来解决这个问题.这有点复杂,但过程几乎相同.

Set up a timer on your app which fires (say) every minute, and check the time in there.

This can be defeated easily by changing the system clock, but you could get round that by fetching the time from an internet supplier. That is a bit more complex, but pretty much the same process.


这篇关于设置软件的时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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