abort thread

rogerm

Member
Joined
Apr 6, 2007
Messages
15
Programming Experience
3-5
When trying to stop a process using a thread.abort I get an error " system null ref. exception in Windows.Form.dll" " Obj ref. not set insatance of Obj" and end up in debug mode with Form1 highlighted in green.When stepping through the code , it goes to error imediatelly after sub "Schedule" is stepped off of.

Any insight would be appreciated.

Also, When I am displaying Form1 and a user control(brought to front) which shows a progress bar, why can I not get access to a button on the form1(abortBtn) to initiate thd.abort?

representative code:

Form1
VB.NET:
dim thd as system.threading.thread
dim abortBtn as new button
 
 
private sub InitSch()
'
'
dim thd as new System.threading.thread(addressof Schedule)
thd.start
end sub
 
 
private Sub Schedule()
'
'
SubA()
SubB()
end Sub
 
private sub abortBtn_click()
thd.abort
end sub
 
private Sub SubA()
 
end sub
 
private Sub SubB()
 
end sub
 
Last edited by a moderator:
What goes wrong: You have declared 'thd' at class level, then in InitSch method you declare a new local variable with same name and start thread by this. Your class level 'thd' is still 'Nothing'. When you click button 'Nothing' is tried aborted.

How to fix it: In InitSch method assign the thread to the class variable instead of declaring it locally again. (thd = New thread... thd.start)
 
Back
Top