Rick, this is the current draft of the code - it still needs some attention ie a WITH and an EXIT FOR wouldn't go amiss - but it is being used and is stable (ot at least seems to be).
It's called with:
OnProgress:
Dim ctrledit As New CMMonthEndProgressUpdater(FForm.pbProgress, FForm.lvTaskList)
Dim s As String
s = ProgressDescription 'Add more fields later
ctrledit.ChangeTaskGrid(EventSource, s)
ctrledit = Nothing
OnStart:
Dim ctrledit As New CMMonthEndProgressUpdater(FForm.pbProgress, FForm.lvTaskList)
ctrledit.ChangeTaskGrid(EventSource, "Started", Now())
ctrledit = Nothing
and OnFinish:
Dim ctrledit As New CMMonthEndProgressUpdater(FForm.pbProgress, FForm.lvTaskList)
ctrledit.ChangeTaskGrid(EventSource, "Finished", , Now())
ctrledit.ChangeProgress()
ctrledit = Nothing
(by the way - EventSource and ProgressDescription come from the DTS event declarations).
Code:
Public Class CMMonthEndProgressUpdater
Private FTask As String
Private FStatus As String
Private FStart As Date
Private FFinish As Date
'Private FDuration As double
Private FPosition As Integer
Private FProgress As RCC.rccProgressBar
Private FTaskGrid As GlacialComponents.Controls.GlacialList
Public Sub New(ByVal AProgress As RCC.rccProgressBar, ByVal ATaskGrid As GlacialComponents.Controls.GlacialList)
FProgress = AProgress
FTaskGrid = ATaskGrid
End Sub
Public Sub ChangeProgress()
'Only called by OnFinish
SyncLock Me
FProgress.Invoke(New MethodInvoker(AddressOf ThreadSafeChangeProgress))
End SyncLock
End Sub
Private Sub ThreadSafeChangeProgress()
FProgress.PerformStep()
FProgress.Refresh()
End Sub
Public Sub ChangeTaskGrid( _
ByVal ATask As String, _
ByVal AStatus As String, _
Optional ByVal AStart As Date = #1/1/1900#, _
Optional ByVal AFinish As Date = #1/1/1900#, _
Optional ByVal APosition As Integer = -1)
'Called by everything
SyncLock Me
FTask = ATask
FStatus = AStatus
FStart = AStart
FFinish = AFinish
FPosition = APosition
FTaskGrid.Invoke(New MethodInvoker(AddressOf ThreadSafeChangeTaskGrid))
End SyncLock
End Sub
Private Sub ThreadSafeChangeTaskGrid()
Dim found As Boolean
found = False
For a As Integer = 0 To FTaskGrid.Items.Count - 1
If FTaskGrid.Items(a).Text = FTask Then
If FStatus = "Finished" Then
If FTaskGrid.Items(a).SubItems(1).Text <> "Started" Then
FTaskGrid.Items(a).SubItems(1).Text = "Finished " + FTaskGrid.Items(a).SubItems(1).Text
Else
FTaskGrid.Items(a).SubItems(1).Text = FStatus
End If
Else
FTaskGrid.Items(a).SubItems(1).Text = FStatus
End If
If FStart <> FDefaultDate Then FTaskGrid.Items(a).SubItems(2).Text = FStart.ToString("hh:mm:ss")
If FFinish <> FDefaultDate Then
FTaskGrid.Items(a).SubItems(3).Text = FFinish.ToString("hh:mm:ss")
'add duration code here
End If
FTaskGrid.Items(a).Selected = True
FTaskGrid.EnsureVisible(a)
found = True
End If
Next
If Not found Then
Dim dtlm As New GlacialComponents.Controls.GLItem
With dtlm
.SubItems(0).Text = FTask
.SubItems(1).Text = FStatus
If FStart <> FDefaultDate Then .SubItems(2).Text = FStart.ToString("hh:mm:ss")
If FFinish <> FDefaultDate Then .SubItems(3).Text = FFinish.ToString("hh:mm:ss")
End With
FTaskGrid.Items.Add(dtlm)
dtlm.Selected = True
FTaskGrid.EnsureVisible(FTaskGrid.Items.Count - 1)
End If
FTaskGrid.Refresh()
FTaskGrid.Focus()
End Sub
End Class
[included for our Belgian friend]
End Module
[/included for our Belgian friend][smile]
Its definitely not perfect, which is why I keep playing with it. I'd be interested in your comments.