aborting thread results in application crash

S

Snuyt

Hello,

I'm using threads to fill a form with multiple controls: In a
listbox.selecteditem_changed, I abort the current thread, and I start a
new thread to fill the form with the data correspondent to the selected
Item. The reason for using threads here is speed (since the filling of
the form takes +/- 0.5 sec). But if I rapidly select some different
items in the listbox (e.g. with the arrow buttons), the application
stops executing, and crashes (CPU-time=100% and not responding). There
doesn't seem to be a critical line of code, it just stops at different
lines... Does anyone knows what the reason is for this ? Here's the code:

private sub lst_selectedindexchanged(...) handles ...
try
thread.abort 'thread is declared private in
'the form class
catch exc as exception
end try
thread=new threading.thread(AddressOf fillForm)
thread.start()
end sub

private sub FillForm()
'here i do stuff like: filling a Combobox,
'setting text for a textbox, ...
end sub


Thanks,

Snuyt
 
T

Tosch

Changing properties of controls not beeing created on the same thread
can lead to these sort of problems.
Use control.invoke to change the properties.

Tosch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top