473,387 Members | 1,536 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,387 software developers and data experts.

Multi thread stops when opening a new form

jt
Below is the code with the problem (it is just one form):
When you run the code, you hear a beep every second, the beep is on a new
thread.
When you push the button 100 forms are opend, the beep should continue, but
is doesn't.
Sometimes it already stops when you open 1 form, but to make sure the sample
works it will open 100 forms.
Who can help me?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ClientSize = New System.Drawing.Size(292, 266)
Dim Button1 As New System.Windows.Forms.Button
Button1.Text = "Open forms"
AddHandler Button1.Click, AddressOf Button1_Click
Me.Controls.Add(Button1)
RunTimer()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim i As Integer
For i = 1 To 100
Dim NewForm As New Form
NewForm.Size = New System.Drawing.Size(152, 62)
NewForm.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
NewForm.Text = i
NewForm.Show()
Next
End Sub
Sub RunTimer()
Dim TimerDelegate As New Threading.TimerCallback(AddressOf TimerTask)
Dim TimerItem As New System.Threading.Timer(TimerDelegate, Nothing,
0, 1000)
End Sub
Sub TimerTask(ByVal StateObj As Object)
Beep()
End Sub

Dec 30 '05 #1
2 1123
"jt" <jt@discussions.microsoft.com> schrieb
Below is the code with the problem (it is just one form):
When you run the code, you hear a beep every second, the beep is on
a new thread.
When you push the button 100 forms are opend, the beep should
continue, but is doesn't.
Sometimes it already stops when you open 1 form, but to make sure
the sample works it will open 100 forms.
Who can help me?


Read the "Hints" section in the documentation on the Timer class: The GC
eats all of them. => declare them as a field in the class.

Armin

Dec 30 '05 #2
jt
Armin, thanks, that was what i was looking for, i had no idea the Garbage
Collection was the problem.
Here is the new code that works (in case someone needs it):

Dim TimerDelegate As New Threading.TimerCallback(AddressOf TimerTask)
Dim TimerItem As New System.Threading.Timer(TimerDelegate, TimerItem, 0,
1000)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ClientSize = New System.Drawing.Size(292, 266)
Dim Button1 As New System.Windows.Forms.Button
Button1.Text = "Open forms"
AddHandler Button1.Click, AddressOf Button1_Click
Me.Controls.Add(Button1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim i As Integer
For i = 1 To 100
Dim NewForm As New Form
NewForm.Size = New System.Drawing.Size(152, 62)
NewForm.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
NewForm.Text = i
NewForm.Show()
Next
End Sub
Sub TimerTask(ByVal StateObj As Object)
Beep()
End Sub
End Class
"Armin Zingler" wrote:
"jt" <jt@discussions.microsoft.com> schrieb
Below is the code with the problem (it is just one form):
When you run the code, you hear a beep every second, the beep is on
a new thread.
When you push the button 100 forms are opend, the beep should
continue, but is doesn't.
Sometimes it already stops when you open 1 form, but to make sure
the sample works it will open 100 forms.
Who can help me?


Read the "Hints" section in the documentation on the Timer class: The GC
eats all of them. => declare them as a field in the class.

Armin

Dec 30 '05 #3

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

Similar topics

1
by: Patrick Toledano | last post by:
Hello, I am building small application using interface with Outlook and Word. The first window is a startup whith a smooth blinking using clock control. This window display upon the second...
5
by: Rob Durant | last post by:
Hi, I have a multi-threaded application (have also tried as service - same behaviour) that runs fine on XP, but not on 2003. Symptoms are: Threads are started normally, locks acquired and...
0
by: Stuart Norris | last post by:
Dear Group, I am attempting to write a "splash" and "status" Form using a second thread. I wish to use this Form to display status information to the user when I do CPU intensive work in my...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
4
by: Max | last post by:
Playing around with multi-threading programs and ran into this little problem that maybe someone here could explain... Basically I have a class which launches a form object. Once the form is...
8
by: PAPutzback | last post by:
How do I keep the form up.
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
6
by: Leon | last post by:
Hi there, I am trying to use the WebBrowser Control in a form which is being started in an own thread by the main form of my application. Unfortunately I am always getting an error in...
3
by: Barkingmadscot | last post by:
I am having problems with Multi-threading and write to Key Access Database I have a log file that and collecting infomation from getting the info is a problem or is writing it the database,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.