abort thread

I have an app that will import some data into a database. I can't seem to stop my worker thread from running. Am I missing something

t = New Thread(AddressOf oPF.ProcessFile)
t.IsBackground = True
oPF.oCnn = SqlConnection1
oPF.myStream = myStream
t.Start()


then in my oPF classs i'm going through the motions of parsing the stream and such. 
My problem comes when i'm trying to pause/stop this thread. 


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If t.IsAlive Then
t.Suspend()
If MsgBox("Operation Paused! Would you like to Cancel ", MsgBoxStyle.YesNo, "Import in Process") = MsgBoxResult.Yes Then
t.Abort()
Else
t.Resume()
End If
End If
End Sub


No matter what the choice it the thread continues to run.  Am I doing something wrong


Answer this question

abort thread

  • Keith Swem

    Hey guys,
    If now I want to restart the thread with say different options, how do I go about doing this.
    when I do a thread.start on a thread that has been aborted, it gives me an error stating that the Thread is currently running or has been aborted, Cannot be restarted.
    Is there a workaround for that

  • Chaitanya Tyagi

    Well, there is really no *guarantee* that the thread will be aborted... I would try adding a call to Join after the Abort:

    t.Abort()
    t.Join()

  • GlenW

    try this

    if ( t != null && t.IsAlive)
    {
    t.Abort();
    t = null;

    }


  • Gerardicus

    I got it. Thanks Again.
  • abort thread