Home All Groups Group Topic Archive Search About

cross Thread not valid

Author
25 Sep 2006 11:50 PM
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

Author
26 Sep 2006 12:06 AM
Herfried K. Wagner [MVP]
<elun***@hotmail.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
26 Sep 2006 2:20 AM
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!


Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> <elun***@hotmail.com> schrieb:
> > 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.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>