472,981 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 software developers and data experts.

Threading Questions (repost)

Bob
- 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
Nov 21 '05 #1
4 1264
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

Nov 21 '05 #2
edit correction - replace hnet with xxx in the previous post

"AMercer" wrote:
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

Nov 21 '05 #3
edit correction - replace hnet with xxx in the previous post

"AMercer" wrote:
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

Nov 21 '05 #4
I was too hasty in the first reply. Also change

Sample uses:
xxxEnqueue("stuff",1.5,true)
dim Data() as object = xxxDequeue()
' data(0)="stuff", data(1)=1.5, and data(2)=true

to

Sample uses:
dim zzz() as object = {"stuff",1.5,true}
xxxEnqueue(zzz)
dim Data() as object = xxxDequeue()
' data(0)="stuff", data(1)=1.5, and data(2)=true

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
4
by: Antal Rutz | last post by:
Hi, All! I'm new to threading. I have some design questions: Task: I collect data and store them in an RDBMS (mysql or pgsql) The question is how to do that with threading? The...
1
by: Jon Sequeira | last post by:
I'm have a class that represents shipping cost data for a commerce web site. The underlying data may only change once a month, maybe less, so I'd rather not hit the database every time the class is...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
by: Phillip N Rounds | last post by:
Why is this using 50% of available CPU? What I am trying to accomplish in this service is as follows: In the main class (COS_Service) , int Main(), initializes a timer. Each OnTimer()...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
9
by: akrapus | last post by:
Hi, I am trying to understand how to use threading in Python. I get threading as a concept, but not the implementation. In order to start threading, do you call it as a separate function,...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.