每1小时后重新启动计算机 [英] Restart computer after every 1 hour

查看:70
本文介绍了每1小时后重新启动计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



i编写以下代码重新启动系统



Hi all

i write the below code to restart a system

 try
            {
if (MessageBox.Show("Are you sure you want to restart your computer?", "Restart",                     MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    ShutDownWindows("2"); // Restart the computer  
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }





这是我在按钮点击活动中写的。



现在我想要的是每1小时它应该自动执行。我不是在寻找任何sql解决方案。



请告诉我该怎么做..



this i wrote on a button click event.

Now i want is every 1 hour it should automatically execute.i am not looking for any sql solution.

please tell me how to do this..

推荐答案

我不知道你为什么要这样做,但是......

你需要设置你的应用程序才能运行在启动时自动启动(Google会提供帮助,对于不同的系统会略有不同)

然后创建一个Timer,将其Interval属性设置为60 * 60 * 1000并处理Tick事件。

将代码添加到处理程序方法。
I don't know why you would want to do that, but...
You will need to set your app to run automatically on startup (Google will help, it's slightly different for different systems)
Then create a Timer, set its Interval property to 60*60*1000 and handle the Tick event.
Add your code to the handler method.


您可以将程序添加到 Windows任务计划程序,您可以在其中选择时间(何时到运行)频率(何时重复)



因此,它会根据您的喜好自动运行。
You can add your program to Windows Task Scheduler, where you can select the Time (when to run) and frequency (when to repeat).

So, it will automatically run as per your preference.


第一种方式



在程序中使用线程< br $> b $ b

1st way

Use Threading in your program

Thread.Sleep (TimeSpan.FromHours (1));  // sleep for 1 hour
Thread.Sleep (500);                     // sleep for 500 milliseconds





第二路



使用Windows服务



在Windows服务中




2nd way

Use Windows service

In Windows Service

Process.Start("path to your program .exe");


这篇关于每1小时后重新启动计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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