Skip to content

Commit 08c4f80

Browse files
committed
增加进程时间控制功能
增加自动刷新
1 parent 1c2de0f commit 08c4f80

File tree

9 files changed

+109
-31
lines changed

9 files changed

+109
-31
lines changed

TCSetup/TCSetup.vdproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
}
147147
"{3C67513D-01DD-4637-8A68-80971EB9504F}:_57FF55C0487B4507A7ADC64F8E5966A5"
148148
{
149-
"DefaultLocation" = "8:[ProgramFilesFolder][Manufacturer]\\[ProductName]"
149+
"DefaultLocation" = "8:[ProgramFiles64Folder][Manufacturer]\\[ProductName]"
150150
"Name" = "8:#1925"
151151
"AlwaysCreate" = "11:FALSE"
152152
"Condition" = "8:"
@@ -183,29 +183,29 @@
183183
{
184184
"Name" = "8:Microsoft Visual Studio"
185185
"ProductName" = "8:TimeControl"
186-
"ProductCode" = "8:{232A368F-8E6F-4FBB-B176-718FE5FE9F46}"
187-
"PackageCode" = "8:{9FEA6838-90F7-4F96-9D10-00374CF5ABA5}"
186+
"ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}"
187+
"PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}"
188188
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
189189
"AspNetVersion" = "8:4.0.30319.0"
190190
"RestartWWWService" = "11:FALSE"
191191
"RemovePreviousVersions" = "11:TRUE"
192192
"DetectNewerInstalledVersion" = "11:TRUE"
193193
"InstallAllUsers" = "11:FALSE"
194-
"ProductVersion" = "8:3.1.0"
194+
"ProductVersion" = "8:3.1.1"
195195
"Manufacturer" = "8:SamHou"
196196
"ARPHELPTELEPHONE" = "8:"
197197
"ARPHELPLINK" = "8:"
198198
"Title" = "8:TCSetup"
199199
"Subject" = "8:"
200200
"ARPCONTACT" = "8:SamHou"
201201
"Keywords" = "8:"
202-
"ARPCOMMENTS" = "8:"
202+
"ARPCOMMENTS" = "8:TimeControl安装程序"
203203
"ARPURLINFOABOUT" = "8:"
204204
"ARPPRODUCTICON" = "8:"
205205
"ARPIconIndex" = "3:0"
206206
"SearchPath" = "8:"
207207
"UseSystemSearchPath" = "11:TRUE"
208-
"TargetPlatform" = "3:0"
208+
"TargetPlatform" = "3:1"
209209
"PreBuildEvent" = "8:"
210210
"PostBuildEvent" = "8:"
211211
"RunPostBuildEvent" = "3:0"
@@ -797,7 +797,7 @@
797797
{
798798
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF"
799799
{
800-
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
800+
"SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
801801
"TargetName" = "8:"
802802
"Tag" = "8:"
803803
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
@@ -825,7 +825,7 @@
825825
}
826826
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
827827
{
828-
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows\\apphost.exe"
828+
"SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
829829
"TargetName" = "8:"
830830
"Tag" = "8:"
831831
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/App.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ public class App
1212
private string location;
1313
public string Name { get { return name; }}
1414
internal int time;
15-
16-
public string ReportApp()
15+
/// <summary>
16+
/// 返回进程的简要概述
17+
/// </summary>
18+
/// <returns>进程的简要概述</returns>
19+
public override string ToString()
1720
{
1821
return Name + " 已使用 " + time+" 秒!";
1922
}
@@ -23,11 +26,17 @@ public App(string name, string location)
2326
this.location = location;
2427
Reset();
2528
}
26-
public virtual void Run()//运行一次(一秒)
29+
/// <summary>
30+
/// 运行一次(一秒)
31+
/// </summary>
32+
public virtual void Run()
2733
{
2834
time++;
2935
}
30-
public void Reset()//重设时间
36+
/// <summary>
37+
/// 重设时间
38+
/// </summary>
39+
public void Reset()
3140
{
3241
time = 0;
3342
}

TimeControl/ControlPanel.Designer.cs

Lines changed: 22 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/ControlPanel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有
118118
private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
119119
{
120120
controller.Run();
121+
if (autoRefreshBox.Checked)
122+
controller.Refresh();
121123
if (Process.GetProcessesByName("TimeControlConsole").Length == 0)//检查保护程序状态
122124
{
123125
ProcessStartInfo process = new();

TimeControl/LimitedApp.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public LimitedApp(string name, string location,int timeLimit) : base(name, locat
1515
{
1616
this.timeLimit = timeLimit;
1717
}
18-
public override void Run()//运行一次(一秒)
18+
/// <summary>
19+
/// 运行一次(一秒),并根据情况显示警告或关闭进程
20+
/// </summary>
21+
public override void Run()
1922
{
2023
base.Run();
2124
if (time == timeLimit - 30)
@@ -28,7 +31,18 @@ public override void Run()//运行一次(一秒)
2831
Ban();
2932
}
3033
}
31-
public void Ban()//禁用掉该程序
34+
/// <summary>
35+
/// 返回时间受限进程的简要概述
36+
/// </summary>
37+
/// <returns>时间受限进程的简要概述</returns>
38+
public override string ToString()
39+
{
40+
return base.ToString() + "进程时间限制为:" + timeLimit + "秒";
41+
}
42+
/// <summary>
43+
/// 禁用掉该程序
44+
/// </summary>
45+
public void Ban()
3246
{
3347
Process[] processes = Process.GetProcessesByName(Name);
3448
foreach (Process process in processes)

TimeControl/ListController.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ public ListController(ListBox listBox,Timer timer)
2121
this.timer = timer;
2222
}
2323

24-
24+
/// <summary>
25+
/// 刷新列表显示
26+
/// </summary>
2527
public void Refresh()
2628
{
2729
timer.Stop();
2830
listBox.Items.Clear();
2931
foreach (App app in apps)
3032
{
31-
listBox.Items.Add(app.ReportApp());
33+
listBox.Items.Add(app.ToString());
3234
}
3335
timer.Start();
3436
}
37+
/// <summary>
38+
/// 根据名称添加进程
39+
/// </summary>
40+
/// <param name="name">要添加的进程名称</param>
3541
public void AddByName(string name)
3642
{
3743
timer.Stop();
@@ -49,6 +55,11 @@ public void AddByName(string name)
4955
}
5056
this.Refresh();
5157
}
58+
/// <summary>
59+
/// 根据名称添加时间受限的进程
60+
/// </summary>
61+
/// <param name="name">进程名称</param>
62+
/// <param name="limitTime">限制时长(秒)</param>
5263
public void AddByName(string name,int limitTime)
5364
{
5465
timer.Stop();
@@ -66,6 +77,9 @@ public void AddByName(string name,int limitTime)
6677
}
6778
this.Refresh();
6879
}
80+
/// <summary>
81+
/// 跟踪所有进程,增加一秒
82+
/// </summary>
6983
public void Run()
7084
{
7185
foreach (App app in apps)//计算进程时间
@@ -82,6 +96,9 @@ public void Run()
8296
}
8397
}
8498
}
99+
/// <summary>
100+
/// 移除所列表所选的进程
101+
/// </summary>
85102
public void Remove()
86103
{
87104
timer.Stop();

TimeControl/TimeControl.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
66
<UseWindowsForms>true</UseWindowsForms>
77
<Authors>SamHou</Authors>
8-
<Version>3.1.0</Version>
8+
<Version>3.1.1</Version>
99
<StartupObject>TimeControl.Program</StartupObject>
1010
<AssemblyVersion></AssemblyVersion>
1111
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
1212
<ApplicationIcon>icons8_sand_watch.ico</ApplicationIcon>
1313
<PlatformTarget>AnyCPU</PlatformTarget>
1414
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
15+
<Platforms>AnyCPU;x64;x86</Platforms>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
1819
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
1920
</PropertyGroup>
2021

22+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
23+
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
24+
</PropertyGroup>
25+
26+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
27+
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
28+
</PropertyGroup>
29+
2130
<ItemGroup>
2231
<Content Include="icons8_sand_watch.ico" />
2332
</ItemGroup>

TimeControlConsole/TimeControlConsole.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
99
<BaseOutputPath>..\TimeControl\bin</BaseOutputPath>
1010
<PlatformTarget>AnyCPU</PlatformTarget>
11+
<Platforms>AnyCPU;x64;x86</Platforms>
1112
</PropertyGroup>
1213

1314
</Project>

时控.sln

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,50 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeControl", "TimeControl\
77
EndProject
88
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "TCSetup", "TCSetup\TCSetup.vdproj", "{36173DC9-6785-40FF-A995-0E2A85487285}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeControlConsole", "TimeControlConsole\TimeControlConsole.csproj", "{3F10963C-5471-4A63-9BA2-8D422B121006}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeControlConsole", "TimeControlConsole\TimeControlConsole.csproj", "{3F10963C-5471-4A63-9BA2-8D422B121006}"
1111
EndProject
1212
Global
1313
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1414
Debug|Any CPU = Debug|Any CPU
15+
Debug|x64 = Debug|x64
1516
Debug|x86 = Debug|x86
1617
Release|Any CPU = Release|Any CPU
18+
Release|x64 = Release|x64
1719
Release|x86 = Release|x86
1820
EndGlobalSection
1921
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2022
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2123
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x64.ActiveCfg = Debug|Any CPU
2225
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x86.ActiveCfg = Debug|Any CPU
2326
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Debug|x86.Build.0 = Debug|Any CPU
2427
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|Any CPU.ActiveCfg = Release|Any CPU
2528
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|Any CPU.Build.0 = Release|Any CPU
26-
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.ActiveCfg = Release|Any CPU
27-
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.Build.0 = Release|Any CPU
29+
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x64.ActiveCfg = Release|x64
30+
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x64.Build.0 = Release|x64
31+
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.ActiveCfg = Release|x86
32+
{DDB08FEE-8108-49EE-9C5B-17B52E6EC51F}.Release|x86.Build.0 = Release|x86
2833
{36173DC9-6785-40FF-A995-0E2A85487285}.Debug|Any CPU.ActiveCfg = Debug
34+
{36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x64.ActiveCfg = Debug
35+
{36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x64.Build.0 = Debug
2936
{36173DC9-6785-40FF-A995-0E2A85487285}.Debug|x86.ActiveCfg = Debug
3037
{36173DC9-6785-40FF-A995-0E2A85487285}.Release|Any CPU.ActiveCfg = Release
3138
{36173DC9-6785-40FF-A995-0E2A85487285}.Release|Any CPU.Build.0 = Release
39+
{36173DC9-6785-40FF-A995-0E2A85487285}.Release|x64.ActiveCfg = Release
40+
{36173DC9-6785-40FF-A995-0E2A85487285}.Release|x64.Build.0 = Release
3241
{36173DC9-6785-40FF-A995-0E2A85487285}.Release|x86.ActiveCfg = Release
3342
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3443
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x64.ActiveCfg = Debug|x64
45+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x64.Build.0 = Debug|x64
3546
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x86.ActiveCfg = Debug|Any CPU
3647
{3F10963C-5471-4A63-9BA2-8D422B121006}.Debug|x86.Build.0 = Debug|Any CPU
3748
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|Any CPU.ActiveCfg = Release|Any CPU
3849
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|Any CPU.Build.0 = Release|Any CPU
39-
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.ActiveCfg = Release|Any CPU
40-
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.Build.0 = Release|Any CPU
50+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x64.ActiveCfg = Release|x64
51+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x64.Build.0 = Release|x64
52+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.ActiveCfg = Release|x86
53+
{3F10963C-5471-4A63-9BA2-8D422B121006}.Release|x86.Build.0 = Release|x86
4154
EndGlobalSection
4255
GlobalSection(SolutionProperties) = preSolution
4356
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)