Results 1 to 3 of 3

Thread: Simple threading problem... [Resolved]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Simple threading problem... [Resolved]

    This is the first day I have tried to use threads. The code below doesnt work for me. It is supposed to call TestSub every 500 ms. I created a blank windows application in VB.NET 2005 Express Edition Beta #2 and paste this directly into the code and run -
    VB Code:
    1. Imports System.Threading
    2. Public Class Form1
    3.     Dim THRD As Thread
    4.  
    5.     Private Shared Sub TestSub()
    6.         MsgBox("Bleh", MsgBoxStyle.Information, "")
    7.         Thread.Sleep(500)
    8.     End Sub
    9.  
    10.     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    11.         THRD = New Thread(AddressOf TestSub)
    12.         THRD.Start()
    13.         THRD.IsBackground = True
    14.     End Sub
    15.  
    16. End Class
    When I click the form, it is supposed to initialize and start the thread. So I click the form... and get the messagebox, and wait a few seconds, nothing has happened. I pause the app and find out, via the intermediate window, THRD.IsAlive = False

    Can anyone please tell me what is wrong with this code? I'm sure its probably some simple thing I've overlooked.

    Edit: Sorry, didnt mention, I need this thread to stay alive, I'm using a loop to keep it running (with a sleep statement), but what is the proper way?
    Last edited by Cade; Sep 27th, 2005 at 05:37 AM.

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