cross Thread not valid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elun219@hotmail.com

    #1

    cross Thread not valid

    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

  • Herfried K. Wagner [MVP]

    #2
    Re: cross Thread not valid

    <elun219@hotmai l.comschrieb:
    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/>

    Comment

    • elun219@hotmail.com

      #3
      Re: cross Thread not valid

      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:
      <elun219@hotmai l.comschrieb:
      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/>

      Comment

      Working...