problem while aborting the thread

Hi,

I'm gettting a problem while terminating a thread .

my problem is while aborting the thread using threadobject.abort it is giving a message " the thread is being aborted".

can any one suggest how to avoid this message .I'm adding the part of the code using threads

-regards

GRK

Dim tr As New Thread(AddressOf funbusygif)

Private Sub funbusygif()

Try

objshowbusy.ShowDialog()

objshowbusy.Dispose()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

-----------------------------------------

tr.start()

'Some other code is running

tr.abort




Answer this question

problem while aborting the thread

  • dchester11

    Threads are for doing calculations, or getting data from a database in the background.    Basically threads are for long running processes that do not require user interaction. Do not show a dialog form in a background thread because the user most close it.

  • Jangid

    The problem why you saw the "abort" error message, is that you catch the ThreadAbortException and bring up a dialog with a try-catch block. You should change your try-catch block to prevent catching this exception.

    You usually don't want to call thread.abort to stop a thread. The thread will end once the function (funbusygif in your case) ends. The thread could check whether it should end itself.



  • problem while aborting the thread