Re 3rd question - The way I queue results from multiple worker threads is
shown below. A typical use of this is to launch threads from a form and
periodically poll the queue in the form via a timer control. Alternatively,
package this in a class that also declares an event, and raise the event when
date is enqueued. (caution re threading, forms, and marshalling.) An array
of objects is handy because you can enqueue pretty much anything that way.
Substitute whatever you want for 'xxx'.
Sample uses:
xxxEnqueue("stuff",1.5,true)
dim Data() as object = xxxDequeue()
' data(0)="stuff", data(1)=1.5, and data(2)=true
Private xxxQueue As New Collections.Queue
Public Sub xxxEnqueue(ByVal ParamArray Data() As Object)
' thread-safely enqueue an array of objects
Dim bAction As Boolean = False ' true if we have something to enqueue
If Not Data Is Nothing Then _
If Data.Length > 0 Then _
If TypeName(Data(0)) = "String" Then _
bAction = True
If bAction Then
Threading.Monitor.Enter(xxxQueue)
HnetQueue.Enqueue(Data)
Threading.Monitor.Exit(xxxQueue)
End If
' raise an event here if you want to
End Sub
Public Function xxxDequeue() As Object()
' thread-safely dequeue and return an array of objects
Dim Data() As Object ' queue entry
Threading.Monitor.Enter(xxxQueue)
If xxxQueue.Count > 0 Then
Data = CType(xxxQueue.Dequeue(), Object())
Else
Data = Nothing
End If
Threading.Monitor.Exit(xxxQueue)
Return Data
End Function
"Bob" wrote:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done?
- It is OK to pass objects out of the thread? (dumb question maybe but I
want to be sure)
- What's the best way to process messages coming out of a thread? I want to
queue them up, but MessageQueue doesn't look like what I need. Should I just
make my own queue class? If so I'll have to worry about enumerator
synchronization... a pointer to a 'best practice' example would be very
helpful.
Bob
"Bob" wrote:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done?
- It is OK to pass objects out of the thread? (dumb question maybe but I
want to be sure)
- What's the best way to process messages coming out of a thread? I want to
queue them up, but MessageQueue doesn't look like what I need. Should I just
make my own queue class? If so I'll have to worry about enumerator
synchronization... a pointer to a 'best practice' example would be very
helpful.
Bob