Results 1 to 9 of 9

Thread: Creating a new thread

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Creating a new thread

    A thread is a fork of operation within the application
    To create a new one put this at top of code under Class but not in a sub
    VB.NET Code:
    1. Private running As Boolean = True
    2. Private t As Threading.Thread
    Then put these in the correct places
    VB.NET Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2. t = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc))
    3. t.IsBackground = True
    4. t.Start()
    5. End Sub
    6.  
    7. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    8. running = False
    9. If t.IsAlive AndAlso (Not t.Join(1000)) Then
    10.      t.Abort()
    11. End If
    12. End Sub
    13.  
    14. Private Sub threadfunc()
    15. While running
    16.       'PUT YOUR CODE HERE
    17. End While
    18. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width