CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Mar 1999
    Location
    Ohio, USA
    Posts
    163

    cannot abort threads

    In one of my multi threading programs I cannot get my threads to abort. I have about 5 threads and the threads starts one at a time. By the time the fifth thread is started the program gets really slow. The program will not execute pass LoadWheelStn1. How should I resolve this problem?
    Code:
     
    Private Sub LoadWheelStn1()
            If sPortOpenFlag = "T" Then
                Dim MyThread1 As New Thread(AddressOf ThreadStn1)
                MyThread1.Start()
            End If
    
        End Sub
    
        Private Sub ThreadStn1()
    
            Dim varRcvBuff1 As Integer
    
            Try
                Thread.Sleep(3000)
                Application.DoEvents()
    
                SyncLock Me
                    varRcvBuff1 = AxAComm1.get_ValueD(900)
                    'do stuff
                End SyncLock
    
    
                Do While (varRcvBuff1 <> 25)
                    Thread.Sleep(331)
                    Application.DoEvents()
                    SyncLock Me
                        varRcvBuff1 = AxAComm1.get_ValueD(900)
                        'do stuff
                    End SyncLock
                Loop
    
                If (varRcvBuff1 = 25) Then
                    varRcvBuff1 = 0
                    LoadWheelStn1()
                    If Thread.CurrentThread.IsAlive Then
                        Thread.CurrentThread.Abort()
                    End If
                End If
    
            Catch ex As Exception
                Select Case Err.Number
                    Case 0
    
                    Case Else
    
                End Select
            Finally
                Thread.CurrentThread.Abort()
    
            End Try
        End Sub
    I am using vb 2005
    Last edited by shaminda; April 17th, 2010 at 03:37 PM.

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

Featured