Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Got it working

2 views
Skip to first unread message

Ben white

unread,
Apr 29, 2008, 6:31:24 PM4/29/08
to
First, thank you very much for your help. You lead me down a right
path. With the help of this article:
http://forums.vbcity.com/forums/topic.asp?tid=123101
and this one:
http://vbcity.com/forums/topic.asp?tid=112111

I sorted out something that seems to work well for the info passing.
In this solution there is a list box that holds tasks and another that
holds messages/errors. The solution goes like this:
1) declare a class to do the work in the form
private m_oTask as clsTask
2) declare the function that dose the work
Private Sub ProcessError(ByVal oErr As clsErr)
lstResults.Items.Add(oErr) ' I have overridden the
ToString to provide meaningful info.
End Sub
3) Declare the delegate
Private Delegate Sub delDoError(ByVal oError As clsErr)
4) Allocate an instrance of the delegate
Private m_delDoError As delDoError
5) Declare a function that the Delegate will use
Public Sub ReceiveError(ByVal oErr As clsErr) Handles
m_oTask.ItHappened
Me.Invoke(m_delDoError, New Object() {oErr})
End Sub
6) In the form constructor, instantiate the delagate
m_delDoError = New delDoError(AddressOf ProcessError)
7) Declare a Thread
Private m_oThread As Thread
8) Set up the call to start the thread (I actually used a timer to
have it process items from the list. It allows the user to add or
remove tasks while another task is running). You need to pass a
reference to the form into the class that will be executing.
Public Sub TimerCheck(...)
m_oTask = new clsTask(me)
m_oThread = New Thread(AddressOf m_oTask.JobToDo)
m_oThread.Start()
End sub
9) The rest happens in the Task class. The New function is overloaded
Public Sub New (ByRef oPrnt as frm)
m_oFrm - frm
End Sub
9) all you have to do now set up the work to do and make calls back.
For this example I am doing it in my JobToDo Function
Public Sub JobToDo()
dim oErr as new clsErr ' definition of this really doesn't
matter
dim iCt as Integer
For iCt = 1 toi 5
if m_oFrm.CancelNow = True then 'CancelNow is set by a
Cancel Button on the form
oErr = New clsErr
oErr.Msg = "I've Been Cancelled"
m_oFrm.ReceiveError(oErr)
Exit Sub
End if
Thread.Sleep(2000) ' imitating some work
oErr = New clsErr
oErr.Msg = "Complete " & iCt.ToString & " units of
work"
m_oFrm.ReceiveError(oErr)
Next
m_oFrm.ReceiveDone() ' another delegate done the same way
End Sub

That is pretty much it. Cancel only cancels the current job and the
timer starts the next one. Interesting to note that this fix also
seems to have helped with the Progress refresh issue. The progress
data was being shown on a different form started by the Task object.

Again, Bill - many thanks. I posted these code portions just in case
anyone else might need a boost getting to the answer.

Bill McCarthy

unread,
Apr 29, 2008, 8:28:59 PM4/29/08
to
Glad it helped :)


"Ben white" <pgwich...@gmail.com> wrote in message
news:a1e1a774-5d50-42d3...@y21g2000hsf.googlegroups.com...

0 new messages