cross Thread not valid

E

elun219

Hi Guys,

I have a question on the Vb.net code I am working on. I have a winform
that has a button that starts a thread, I would like to close the
winform when thread finishes or crashes. Is there a way to call
winform.close from the thread?

Thank you

Alan
 
H

Herfried K. Wagner [MVP]

I have a question on the Vb.net code I am working on. I have a winform
that has a button that starts a thread, I would like to close the
winform when thread finishes or crashes. Is there a way to call
winform.close from the thread?

Yes, you can call it by calling the form's 'Invoke' or 'BeginInvoke' method.
 
E

elun219

Thanks a lot for helping. My code looks like the following:
private sub run()
try
calculate()
winform.close
catch ex
winform.close
end try
end function

public sub button1_onclick()
dim a as thread (addressof run)
a.start
end sub

Can you help point out where I should use invoke and beginInvoke?

Thank you!
 

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