資源簡介
自動重啟某個進程,CPU占用率檢測,采用C#編寫,使用守護程序可以提高系統的穩定性。當然這是我項目中的一部分,有些地方還要改一改才能用。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Diagnostics;
using?System.Runtime.InteropServices;
using?System.Threading;
using?Microsoft.Win32;
namespace?Demo
{
????public?partial?class?AutoRestart?:?Form
????{
????????#region?Dll引用函數聲明
????????///?
????????///?參數說明:section:INI文件中的段落名稱;key:INI文件中的關鍵字;
????????///?def:無法讀取時候時候的缺省數值;retVal:讀取數值;size:數值的大小;
????????///?filePath:INI文件的完整路徑和名稱。
????????///?
????????///?
????????///?
????????///?
????????///?
????????///?
????????///?
????????///?
????????[DllImport(“kernel32“)]
????????public?static?extern?int?GetPrivateProfileString(string?section
????????????string?key
????????????string?def
????????????StringBuilder?retVal
????????????int?size
????????????string?filePath);
????????#endregion
????????private?bool?isStart;
????????private?Thread?reStartThrd;
????????private?static?System.Threading.Timer?aTimer?=?null;
????????public?AutoRestart()
????????{
????????????InitializeComponent();
????????????RunWhenStart(true?“demo“?@“D:\Demo“);
????????????RunWhenStart(false?“pcdvr“?@“C:\Program?Files\SCUT\PCDVRMonitor\PCDVRMonitor.exe“);
????????}
????????public?bool?IsStart
????????{
????????????get
????????????{
????????????????return?isStart;
????????????}
????????}
????????public?void?start()
????????{
????????????isStart?=?true;
????????????reStartThrd?=?new?Thread(new?ParameterizedThreadStart(restart));
????????????reStartThrd.Start();
????????}
????????public?void?stop()
????????{
????????????if?(this.reStartThrd?!=?null)
????????????{
????????????????if?(?this.reStartThrd.ThreadState?==?System.Threading.ThreadState.WaitSleepJoin)
????????????????{
????????????????????this.reStartThrd.Interrupt();
????????????????}
????????????????isStart?=?false;
????????????????this.reStartThrd.Join();
????????????}
????????}
????????private?void?restart(object?obj)
????????{
????????????aTimer?=?new?System.Threading.Timer(TimeEvent?null?1000?1000?*?60);
????????}
????????public?void?TimeEvent(object?obj)
????????{
????????????DateTime?now?=?DateTime.Now;
????????????int?size?=?255;
????????????int?count?hour?minute;
????????????DayOfWeek?day;
????????????StringBuilder?retVal?=?new?StringBuilder(size);
????????????GetPrivateProfileString(“restart“?“count“?““?retVal?size?@“C:\Program?Files\SCUT\PCDVRMonitor\pcdvr.ini“);
????????????count?=?Convert.ToInt32(retVal.ToString());
????????????GetPrivateProfileString(“restart“?“hour“?““?retVal?size?@“C:\Program?Files\SCUT\PCDVRMonitor\pcdvr.ini“);
????????????hour?=?Convert.ToInt32(retVal.ToString());
???????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9981??2010-03-25?11:41??Demo開機啟動svchost\Demo\AutoRestart.cs
?????文件???????3336??2010-03-24?16:12??Demo開機啟動svchost\Demo\AutoRestart.Designer.cs
?????文件??????20614??2010-03-24?16:12??Demo開機啟動svchost\Demo\AutoRestart.resx
?????文件??????40960??2010-03-20?15:11??Demo開機啟動svchost\Demo\bin\Debug\Demo.exe
?????文件??????24064??2010-03-20?15:11??Demo開機啟動svchost\Demo\bin\Debug\Demo.pdb
?????文件???????5632??2005-11-11?22:25??Demo開機啟動svchost\Demo\bin\Debug\Demo.vshost.exe
?????文件????????105??2010-03-20?15:23??Demo開機啟動svchost\Demo\bin\Debug\pcdvr.ini
?????文件??????40960??2010-03-25?11:42??Demo開機啟動svchost\Demo\bin\Release\Demo.exe
?????文件??????26112??2010-03-25?11:42??Demo開機啟動svchost\Demo\bin\Release\Demo.pdb
?????文件???????5632??2005-11-11?22:25??Demo開機啟動svchost\Demo\bin\Release\Demo.vshost.exe
?????文件?????????57??2010-03-20?15:41??Demo開機啟動svchost\Demo\bin\Release\pcdvr.ini
?????文件???????3361??2010-03-24?11:32??Demo開機啟動svchost\Demo\Demo.csproj
?????文件???????9662??2010-03-20?15:11??Demo開機啟動svchost\Demo\Icon.ico
?????文件??????10228??2010-03-20?15:11??Demo開機啟動svchost\Demo\obj\Debug\Demo.AutoRestart.resources
?????文件????????848??2010-03-20?15:11??Demo開機啟動svchost\Demo\obj\Debug\Demo.csproj.GenerateResource.Cache
?????文件??????40960??2010-03-20?15:11??Demo開機啟動svchost\Demo\obj\Debug\Demo.exe
?????文件??????24064??2010-03-20?15:11??Demo開機啟動svchost\Demo\obj\Debug\Demo.pdb
?????文件????????180??2010-03-20?15:11??Demo開機啟動svchost\Demo\obj\Debug\Demo.Properties.Resources.resources
?????文件????????522??2010-03-25?11:42??Demo開機啟動svchost\Demo\obj\Demo.csproj.FileList.txt
?????文件??????10228??2010-03-25?11:41??Demo開機啟動svchost\Demo\obj\Release\Demo.AutoRestart.resources
?????文件????????848??2010-03-25?11:41??Demo開機啟動svchost\Demo\obj\Release\Demo.csproj.GenerateResource.Cache
?????文件??????40960??2010-03-25?11:42??Demo開機啟動svchost\Demo\obj\Release\Demo.exe
?????文件??????26112??2010-03-25?11:42??Demo開機啟動svchost\Demo\obj\Release\Demo.pdb
?????文件????????180??2010-03-25?11:41??Demo開機啟動svchost\Demo\obj\Release\Demo.Properties.Resources.resources
?????文件????????469??2010-03-18?16:10??Demo開機啟動svchost\Demo\Program.cs
?????文件???????1180??2010-03-18?09:41??Demo開機啟動svchost\Demo\Properties\AssemblyInfo.cs
?????文件???????2821??2010-03-18?09:41??Demo開機啟動svchost\Demo\Properties\Resources.Designer.cs
?????文件???????5612??2010-03-18?09:41??Demo開機啟動svchost\Demo\Properties\Resources.resx
?????文件???????1087??2010-03-18?09:41??Demo開機啟動svchost\Demo\Properties\Settings.Designer.cs
?????文件????????249??2010-03-18?09:41??Demo開機啟動svchost\Demo\Properties\Settings.settings
............此處省略17個文件信息
評論
共有 條評論