Skip to content

Commit 7f9514f

Browse files
committed
bug fix
1 parent 2e33c4d commit 7f9514f

File tree

5 files changed

+55
-44
lines changed

5 files changed

+55
-44
lines changed

TCSetup/TCSetup.vdproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,21 @@
172172
{
173173
"Name" = "8:Microsoft Visual Studio"
174174
"ProductName" = "8:TimeControl"
175-
"ProductCode" = "8:{2BC11DA4-CD84-437D-A082-79AFF40F938A}"
176-
"PackageCode" = "8:{4758052E-E293-4206-9BC6-5FE53A2FD9B8}"
175+
"ProductCode" = "8:{0E4B2419-C67F-4087-B60D-68E342D1166C}"
176+
"PackageCode" = "8:{C0B174F2-8D69-408C-BE9C-66606508CB47}"
177177
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
178178
"AspNetVersion" = "8:4.0.30319.0"
179179
"RestartWWWService" = "11:FALSE"
180180
"RemovePreviousVersions" = "11:TRUE"
181181
"DetectNewerInstalledVersion" = "11:TRUE"
182182
"InstallAllUsers" = "11:FALSE"
183-
"ProductVersion" = "8:3.0.0"
183+
"ProductVersion" = "8:3.0.1"
184184
"Manufacturer" = "8:SamHou"
185185
"ARPHELPTELEPHONE" = "8:"
186186
"ARPHELPLINK" = "8:"
187187
"Title" = "8:TCSetup"
188188
"Subject" = "8:"
189-
"ARPCONTACT" = "8:Default Company Name"
189+
"ARPCONTACT" = "8:SamHou"
190190
"Keywords" = "8:"
191191
"ARPCOMMENTS" = "8:"
192192
"ARPURLINFOABOUT" = "8:"
@@ -722,7 +722,7 @@
722722
{
723723
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
724724
{
725-
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
725+
"SourcePath" = "8:..\\TimeControl\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe"
726726
"TargetName" = "8:"
727727
"Tag" = "8:"
728728
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/ControlPanel.Designer.cs

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

TimeControl/ControlPanel.cs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace TimeControl
1515
{
1616
public partial class ControlPanel : Form
1717
{
18-
bool closable = false;
19-
List<App> appList = new List<App>();
18+
private bool closable = false;
19+
List<App> appList = new();
2020
#region Dllimport
2121

2222
[Flags]
@@ -118,7 +118,7 @@ public ControlPanel()
118118
InitializeComponent();
119119
}
120120

121-
private void startButton_Click(object sender, EventArgs e)
121+
private void StartButton_Click(object sender, EventArgs e)
122122
{
123123
IntPtr nowDesktop = GetThreadDesktop(GetCurrentThreadId());
124124
IntPtr newDesktop = CreateDesktop("Lock", null, null, 0, ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
@@ -133,7 +133,7 @@ private void startButton_Click(object sender, EventArgs e)
133133
CloseDesktop(newDesktop);
134134
}
135135

136-
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
136+
private void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
137137
{
138138
Show();
139139
}
@@ -153,52 +153,62 @@ private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
153153
Close();
154154
}
155155

156-
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
156+
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
157157
{
158158
Process.Start("explorer.exe", "https://icons8.com/icon/19614/icon");
159159
}
160160

161-
private void backgroundProcessMonitor_DoWork(object sender, DoWorkEventArgs e)
162-
{
163-
while (true)
164-
{
165-
foreach (App app in appList)//计算进程时间
166-
{
167-
if (Process.GetProcessesByName(app.Name).Length != 0)
168-
{ app.Run(); }
169-
}
170-
Thread.Sleep(1000);
171-
}
172-
}
173-
174161
private void ControlPanel_Load(object sender, EventArgs e)
175162
{
176-
backgroundProcessMonitor.RunWorkerAsync();
163+
processMonitorTimer.Start();
177164
}
178-
179-
private void appAddButton_Click(object sender, EventArgs e)//添加打开的窗口
165+
166+
private void AppAddButton_Click(object sender, EventArgs e)//添加打开的窗口
180167
{
168+
processMonitorTimer.Stop();
181169
appList.Clear();
182170
Process[] processes = Process.GetProcesses();
183171
foreach (Process process in processes)
184172
{
185173
if (!string.IsNullOrEmpty(process.MainWindowTitle))
186174
{
187-
appList.Add(new App(process.ProcessName, process.MainModule.FileName));
175+
try
176+
{
177+
appList.Add(new App(process.ProcessName, process.MainModule.FileName));
178+
}
179+
catch (Exception ex)
180+
{
181+
MessageBox.Show(ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);//防止无法访问错误
182+
}
188183
}
189184
}
190-
ListBoxController.Refresh(usageBox, appList);
185+
CalculateTime();
191186
}
192187

193-
private void removeButton_Click(object sender, EventArgs e)//移除所有的已添加窗口
188+
private void RemoveButton_Click(object sender, EventArgs e)//移除所有的已添加窗口
194189
{
195190
appList.Clear();
196-
ListBoxController.Refresh(usageBox, appList);
191+
CalculateTime();
192+
}
193+
194+
private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间
195+
{
196+
CalculateTime();
197197
}
198198

199-
private void refreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间
199+
private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
200+
{
201+
foreach (App app in appList)//计算进程时间
202+
{
203+
if (Process.GetProcessesByName(app.Name).Length != 0)
204+
{ app.Run(); }
205+
}
206+
}
207+
private void CalculateTime()//将进程时间推送到ListBox控件
200208
{
209+
processMonitorTimer.Stop();
201210
ListBoxController.Refresh(usageBox, appList);
211+
processMonitorTimer.Start();
202212
}
203213
}
204214
}

TimeControl/ControlPanel.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@
159159
A///wAP//8AD//8AAP//AAD//+AH////////////
160160
</value>
161161
</data>
162-
<metadata name="backgroundProcessMonitor.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
163-
<value>337, 17</value>
162+
<metadata name="processMonitorTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
163+
<value>374, 20</value>
164164
</metadata>
165165
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
166166
<value>

TimeControl/TimeControl.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
66
<UseWindowsForms>true</UseWindowsForms>
77
<Authors>SamHou</Authors>
8-
<Version>3.0.0</Version>
8+
<Version>3.0.1</Version>
99
<StartupObject>TimeControl.Program</StartupObject>
1010
<AssemblyVersion></AssemblyVersion>
1111
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>

0 commit comments

Comments
 (0)