473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VB.NET Thread Garbage Collection

Hey guys, I'm attempting to create an event scheduler though VB.Net
2005 using threads.
The basic idea is that I can have up to 10 threads going at any given
time. Once a thread finishes I need to be able to "recycle" it so I
can use it again when necessary. Since there is no way to
"reinitialize" a thread I devised this method.

Thread1 = New System.Threading.Thread(AddressOf Task1.ExecuteShell)

If (Thread1.IsAlive = False) Then
If (ResetFlag1 = True) Then
Thread1 = Nothing
GC.Collect()
Thread1 = New System.Threading.Thread(AddressOf
Task1.ExecuteShell)
End If
Task1.EventID = "1"
Task1.TimerValue = Me.TimerBox.Text
Thread1.Start()
ResetFlag1 = True
End if

Basically what happens is that once the thread is used I set it to
Nothing, do a GC.Collect and reset the thread to a new thread. Now my
question here is will this eventually blow up because I keep creating
new instances of the thread object? Or will the garbage collection I
have implimented take care of it?

I'm not using a "threadqueue" because I need to have direct control
over the threads. Any help you could give me would be great

Mar 20 '06 #1
6 7808
Matt wrote:
Hey guys, I'm attempting to create an event scheduler though VB.Net
2005 using threads.
The basic idea is that I can have up to 10 threads going at any given
time. Once a thread finishes I need to be able to "recycle" it so I
can use it again when necessary. Since there is no way to
"reinitialize" a thread I devised this method.

Thread1 = New System.Threading.Thread(AddressOf Task1.ExecuteShell)

If (Thread1.IsAlive = False) Then
If (ResetFlag1 = True) Then
Thread1 = Nothing
GC.Collect()
Thread1 = New System.Threading.Thread(AddressOf
Task1.ExecuteShell)
End If
Task1.EventID = "1"
Task1.TimerValue = Me.TimerBox.Text
Thread1.Start()
ResetFlag1 = True
End if

Basically what happens is that once the thread is used I set it to
Nothing, do a GC.Collect and reset the thread to a new thread. Now my
question here is will this eventually blow up because I keep creating
new instances of the thread object? Or will the garbage collection I
have implimented take care of it?

I'm not using a "threadqueue" because I need to have direct control
over the threads. Any help you could give me would be great


You should not blow up and you should not call GC.Collect. The garbage
collector will handle cleaning up your old threads on its own time frame.

Chris
Mar 20 '06 #2
Matt,

Why do you need direct control over the threads? The reason I'm asking
is because there might be a better solution.

Brian

Matt wrote:
Hey guys, I'm attempting to create an event scheduler though VB.Net
2005 using threads.
The basic idea is that I can have up to 10 threads going at any given
time. Once a thread finishes I need to be able to "recycle" it so I
can use it again when necessary. Since there is no way to
"reinitialize" a thread I devised this method.

Thread1 = New System.Threading.Thread(AddressOf Task1.ExecuteShell)

If (Thread1.IsAlive = False) Then
If (ResetFlag1 = True) Then
Thread1 = Nothing
GC.Collect()
Thread1 = New System.Threading.Thread(AddressOf
Task1.ExecuteShell)
End If
Task1.EventID = "1"
Task1.TimerValue = Me.TimerBox.Text
Thread1.Start()
ResetFlag1 = True
End if

Basically what happens is that once the thread is used I set it to
Nothing, do a GC.Collect and reset the thread to a new thread. Now my
question here is will this eventually blow up because I keep creating
new instances of the thread object? Or will the garbage collection I
have implimented take care of it?

I'm not using a "threadqueue" because I need to have direct control
over the threads. Any help you could give me would be great


Mar 20 '06 #3
Brian,

Basically what we are doing is creating an event scheduler using
threads in the form of a service. Each thread will spawn off an XLNT
shell that will execute a job. I need to be able to halt a job if I
need to, change the priority, and to check to see if the XLNT shell is
still responding. Because of this it's my understanding that I need to
have direct control over the threads. Everything I have read about the
threadqueue which is the other way I thought about handling it,
indicates that I wont have this type of control.

Chris,

So even though this program will potentially be running for months and
months without restarting, the GC should be automatic?

Mar 21 '06 #4
Matt wrote:
Brian,

Basically what we are doing is creating an event scheduler using
threads in the form of a service. Each thread will spawn off an XLNT
shell that will execute a job. I need to be able to halt a job if I
need to, change the priority, and to check to see if the XLNT shell is
still responding. Because of this it's my understanding that I need to
have direct control over the threads. Everything I have read about the
threadqueue which is the other way I thought about handling it,
indicates that I wont have this type of control.

Chris,

So even though this program will potentially be running for months and
months without restarting, the GC should be automatic?


Yes. The developer should never have to deal the GC.

Chris
Mar 21 '06 #5
Matt,

Yeah, I think you're taking the right approach. I believe you're
talking about the ThreadPool when you say "threadqueue". The
ThreadPool is really intended for work items that run quickly. I
suspect your XLNT jobs do not fall into that category. Also, you won't
be able to easily terminate a work item in the ThreadPool whereas you
can always use Thread.Abort as a last resort if running the job in a
single thread. Though, I recommend avoiding Thread.Abort if at all
possible.

Brian
Matt wrote:
Brian,

Basically what we are doing is creating an event scheduler using
threads in the form of a service. Each thread will spawn off an XLNT
shell that will execute a job. I need to be able to halt a job if I
need to, change the priority, and to check to see if the XLNT shell is
still responding. Because of this it's my understanding that I need to
have direct control over the threads. Everything I have read about the
threadqueue which is the other way I thought about handling it,
indicates that I wont have this type of control.

Chris,

So even though this program will potentially be running for months and
months without restarting, the GC should be automatic?


Mar 21 '06 #6
Yes, "threadpool" sorry I'm new to .net :-)

As far as the Thread.Abort function we will only be using that once in
a blue moon. But we need to have the option.

Thanks again guys for your confirmations!

Cheers!

Mar 22 '06 #7

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

Similar topics

1
by: Kent Johnson | last post by:
If I create and start a thread without keeping a reference to the thread, when is the thread garbage collected? What I would like is for the thread to run to completion, then be GCed. I can't...
0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
6
by: NutJob | last post by:
Hello all, I'm aware that in Python an object is cleared for garbage collection as soon as the last reference to it disappears. Normally this is fine. However, in my current project I'm creating...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
11
by: PJ | last post by:
I'd like to create a subsystem in my asp.net application that is responsible for emails that need to be send out based upon certain events so that the main request/response threads aren't...
8
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.