Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi programmers


I have an application that contain a timer that creat new thread each 1000 milliseconds

my code here

VB
<pre>
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim t1 As New Thread(AddressOf ex1)

        t1.Start()

    End Sub

Privat Sub ex1()

......  A whole lot of code here   .......

End Sub

Each 1000 milliseconds the timer creat new thread
but this thread still running , after 1 One minute my application stops working and crashes .

How to stop first before creating the other
Posted
Updated 20-Sep-13 7:33am
v2
Comments
[no name] 20-Sep-13 12:40pm    
"How to stop first before creating the other", redesign your application code so you do not have to.
Michael Azzar 20-Sep-13 12:44pm    
What is your suggestion for the code
[no name] 20-Sep-13 12:47pm    
There is nothing to suggest. I have no idea what "A whole lot of code here" means, what you are doing and I am all out of mind reading potions.
Sergey Alexandrovich Kryukov 20-Sep-13 13:30pm    
Is it VB.NET or VB?
—SA
Michael Azzar 20-Sep-13 13:33pm    
sorry for my tag ,
it is vb.net

1 solution

Whatever are you doing, you are doing it badly. Please consider to re-design your application. This is my humble opinion, of course.
 
Share this answer
 
Comments
Michael Azzar 20-Sep-13 14:15pm    
This is my code can you tell me how to execute it each 1000 M Seconds


Private sub ex1()
Dim sql as string ="Select * From UpdatTable Where ID =' " & Textbox1.text &" ' "


If con.State() Then con.Close()
con.Open()
Try
Dim cmd As New OleDbCommand(sql, con)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()
Dim s As String = ""


While dr.Read
str &= Convert.ToString(dr.Item("UserName")) & vbCrLf
End While
TextBox1.Text = str

Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
con.Close()

End sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900