Skip to content

Commit 814c93d

Browse files
committed
Added warning message for closing window while running tasks.
1 parent d5cd75c commit 814c93d

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

OKEGui/OKEGui/Gui/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
mc:Ignorable="d"
8+
Closing="MainWindow_Closing"
89
Title="OKEGui" Height="600" Width="1000" WindowStartupLocation="CenterScreen" Icon="App.ico">
910
<Window.Resources>
1011
<Style TargetType="ListViewItem">

OKEGui/OKEGui/Gui/MainWindow.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.Reflection;
45
using System.Windows;
@@ -200,5 +201,23 @@ private void AfterFinish_SelectionChanged(object sender, SelectionChangedEventAr
200201
break;
201202
}
202203
}
204+
205+
void MainWindow_Closing(object sender, CancelEventArgs e)
206+
{
207+
if (wm.IsRunning)
208+
{
209+
string msg = "有任务正在运行,确定退出?如果确定退出,记得自己开任务管理器,清理在跑的任务;点击No取消。";
210+
MessageBoxResult result =
211+
MessageBox.Show(
212+
msg,
213+
"没手滑吧?",
214+
MessageBoxButton.YesNo,
215+
MessageBoxImage.Warning);
216+
if (result == MessageBoxResult.No)
217+
{
218+
e.Cancel = true;
219+
}
220+
}
221+
}
203222
}
204223
}

OKEGui/OKEGui/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
4848
// 方法是按如下所示使用“*”: :
4949
// [assembly: AssemblyVersion("1.0.*")]
50-
[assembly: AssemblyVersion("5.2.*")]
50+
[assembly: AssemblyVersion("5.4.*")]

OKEGui/OKEGui/Worker/ExecuteTaskService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
1818
{
1919
WorkerArgs args = (WorkerArgs)e.Argument;
2020

21-
while (isRunning)
21+
while (IsRunning)
2222
{
2323
TaskDetail task = args.taskManager.GetNextTask();
2424

@@ -32,7 +32,7 @@ private void WorkerDoWork(object sender, DoWorkEventArgs e)
3232

3333
if (bgworkerlist.Count == 0)
3434
{
35-
isRunning = false;
35+
IsRunning = false;
3636
Debugger.Log(0, "", "Ready to call the after finish process\n");
3737
AfterFinish?.Invoke();
3838
}

OKEGui/OKEGui/Worker/WorkerManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class WorkerManager
3434

3535
private ConcurrentDictionary<string, BackgroundWorker> bgworkerlist;
3636
private int tempCounter;
37-
private bool isRunning;
37+
public bool IsRunning { get; protected set; }
3838

3939
public delegate void Callback();
4040

@@ -46,14 +46,14 @@ public WorkerManager(TaskManager taskManager)
4646
bgworkerlist = new ConcurrentDictionary<string, BackgroundWorker>();
4747
workerType = new ConcurrentDictionary<string, WorkerType>();
4848
tm = taskManager;
49-
isRunning = false;
49+
IsRunning = false;
5050
tempCounter = 0;
5151
}
5252

5353
public void AddTask(TaskDetail detail)
5454
{
5555
tm.AddTask(detail);
56-
if (isRunning)
56+
if (IsRunning)
5757
{
5858
foreach (string worker in workerList)
5959
{
@@ -77,7 +77,7 @@ public bool Start()
7777
}
7878

7979
int activeTaskCount = tm.GetActiveTaskCount();
80-
isRunning = true;
80+
IsRunning = true;
8181

8282
foreach (string worker in workerList)
8383
{
@@ -150,7 +150,7 @@ public string AddTempWorker()
150150
workerType.TryAdd(name, WorkerType.Temporary);
151151
}
152152

153-
if (isRunning)
153+
if (IsRunning)
154154
{
155155
CreateWorker(name);
156156
StartWorker(name);
@@ -172,7 +172,7 @@ public bool AddWorker(string name)
172172
workerType.TryAdd(name, WorkerType.Normal);
173173
}
174174

175-
if (isRunning)
175+
if (IsRunning)
176176
{
177177
CreateWorker(name);
178178
StartWorker(name);
@@ -183,7 +183,7 @@ public bool AddWorker(string name)
183183

184184
public bool DeleteWorker(string name)
185185
{
186-
if (isRunning)
186+
if (IsRunning)
187187
{
188188
return false;
189189
}
@@ -199,7 +199,7 @@ public bool DeleteWorker(string name)
199199
public void StopWorker(string name)
200200
{
201201
// TODO
202-
isRunning = false;
202+
IsRunning = false;
203203

204204
if (bgworkerlist.ContainsKey(name))
205205
{

0 commit comments

Comments
 (0)