Skip to content

Commit 45909e1

Browse files
committed
Add task bundle feature AllowCancellation
1 parent 47d05a8 commit 45909e1

5 files changed

Lines changed: 54 additions & 4 deletions

File tree

CompuMaster.TaskManagement.UI.WinForms/CompuMaster.TaskManagement.UI.WinForms.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>2024.11.12.101</Version>
4+
<Version>2024.11.12.102</Version>
55
<Copyright>2023-2024 CompuMaster GmbH</Copyright>
66
<Title>CompuMaster.TaskManagement.UI.WinForms - MIT license edition</Title>
77
<Company>CompuMaster GmbH</Company>

CompuMaster.TaskManagement.UI.WinForms/MultiTaskProgessForm.vb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ Public Class MultiTaskProgessForm
2828

2929
Public Property AutoStartTaskBundleRunner As Boolean
3030

31+
Public Property AllowCancellation As Boolean = True
32+
3133
Private Sub MultiTaskProgessForm_Load(sender As Object, e As EventArgs) Handles Me.Load
3234
RefreshAllControls()
35+
If Me.AllowCancellation = False Then Me.ControlBox = False
3336
If AutoStartTaskBundleRunner Then
3437
Me.ButtonStart_Click(sender, e)
3538
End If
@@ -47,9 +50,9 @@ Public Class MultiTaskProgessForm
4750

4851
Public Sub RefreshButtonStatus()
4952
Me.ButtonStart.Visible = Me.TaskBundle.Status = ProgressingTaskBundle.ProgressingTaskBundleStatus.NotStarted
50-
Me.ButtonCancel.Visible = Me.TaskBundle.IsRunningOrFailing
53+
Me.ButtonCancel.Visible = Me.AllowCancellation AndAlso Me.TaskBundle.IsRunningOrFailing
5154
Me.ButtonCancel.Enabled = Not Me.TaskBundle.CancellationTokenSource.Token.IsCancellationRequested
52-
Me.ButtonClose.Visible = Not (Me.ButtonStart.Visible OrElse Me.ButtonCancel.Visible)
55+
Me.ButtonClose.Visible = Not (Me.ButtonStart.Visible OrElse Me.TaskBundle.IsRunningOrFailing)
5356
End Sub
5457

5558
Public Sub RefreshVisibilityAndStatusOfProgressbars()

CompuMaster.TaskManagement.UIDemoApp/DummyTaskBundles.vb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,34 @@ Public NotInheritable Class DummyTaskBundles
140140
Return Result
141141
End Function
142142

143+
Public Delegate Sub DummyTaskBundleResultDataCallReference()
144+
145+
''' <summary>
146+
''' Dummy Task Bundle with data result to be displayed in new form
147+
''' </summary>
148+
''' <returns></returns>
149+
Public Shared Function DummyTaskBundleProvidingSomeResultData(resultAction As DummyTaskBundleResultDataCallReference) As ProgressingTaskBundle
150+
Dim Result As New ProgressingTaskBundle("Dummy Task Bundle for successful run")
151+
Dim Task1 As ProgressingTaskItem = Result.CreateAndAddNewTask("Dummy Task 1")
152+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.1", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
153+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.2", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
154+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.3", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
155+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.4", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
156+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.5", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
157+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.6", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
158+
Task1.FirstStepsWhichCanBeRolledBack.Add(New ProgressingTaskFailFastStep("Dummy Step 1.7", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1)))
159+
Task1.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Step 2.1", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
160+
Task1.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Step 2.2", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
161+
Task1.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Step 2.3", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
162+
Task1.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Step 2.4", Sub() resultAction(), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
163+
Task1.RollbackSteps.Add(New ProgressingTaskStep("Dummy Rollback Step 1", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
164+
Task1.RollbackSteps.Add(New ProgressingTaskStep("Dummy Rollback Step 2", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
165+
Task1.RollbackSteps.Add(New ProgressingTaskStep("Dummy Rollback Step 3", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
166+
Task1.RollbackSteps.Add(New ProgressingTaskStep("Dummy Rollback Step 4", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
167+
Dim Task2 As ProgressingTaskItem = Result.CreateAndAddNewTask("Dummy Task 2")
168+
Task2.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Task 2 Step 1", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
169+
Task2.SecondStepsWithoutRollbackOption.Add(New ProgressingTaskStep("Dummy Task 2 Step 2", Sub() Threading.Thread.Sleep(1000), New TimeSpan(0, 0, 1), ProgressingTaskStep.ProgressingTaskStepFailAction.LogExceptionAndContinue))
170+
Return Result
171+
End Function
172+
143173
End Class

CompuMaster.TaskManagement.UIDemoApp/MainForm.vb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Public Class MainForm
4242
Private Sub TestVonLongRunTaskBundlesButton_Click(sender As Object, e As EventArgs) Handles TestVonLongRunTaskBundlesButton.Click
4343
TryRun(Sub()
4444
Dim f As MultiTaskProgessForm
45+
46+
'Run tasks which doesn't use result data
4547
f = New MultiTaskProgessForm(DummyTaskBundles.DummyTaskBundleFailingWithRollback)
4648
f.Show()
4749
f = New MultiTaskProgessForm(DummyTaskBundles.DummyTaskBundleFailingWithRollbackFailingWithThrownException)
@@ -52,6 +54,21 @@ Public Class MainForm
5254
f.Show()
5355
f = New MultiTaskProgessForm(DummyTaskBundles.DummyTaskBundleSuccessful)
5456
f.Show()
57+
58+
'Run tasks which provide result data and which shall be displayed at GUI
59+
Dim TaskBundleResult As DateTime
60+
Dim tb = DummyTaskBundles.DummyTaskBundleProvidingSomeResultData(Sub() TaskBundleResult = Now)
61+
f = New MultiTaskProgessForm(tb)
62+
f.AutoStartTaskBundleRunner = True
63+
f.AutoCloseFormOnTaskBundleCompleted = True
64+
f.AllowCancellation = False
65+
f.OnTaskBundleCompletedActions.Add(Sub()
66+
Dim f2 As New Form
67+
f2.Text = "Results of " & tb.TaskBundleTitle
68+
f2.Controls.Add(New Label() With {.Dock = DockStyle.Fill, .TextAlign = ContentAlignment.MiddleCenter, .Text = "Task bundle completed on " & TaskBundleResult.ToString})
69+
f2.Show()
70+
End Sub)
71+
f.Show()
5572
End Sub, False, False)
5673
End Sub
5774

CompuMaster.TaskManagement/CompuMaster.TaskManagement.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>2024.11.12.101</Version>
3+
<Version>2024.11.12.102</Version>
44
<Copyright>2023-2024 CompuMaster GmbH</Copyright>
55
<RootNamespace>CompuMaster.TaskManagement</RootNamespace>
66
<TargetFrameworks>netstandard2.0;net6.0;net48</TargetFrameworks>

0 commit comments

Comments
 (0)