Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Howto Start a form in a thread and get access to it's variables

Howto Start a form in a thread and get access to it's variables

Scheduled Pinned Locked Moved C#
questiontutorial
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ariadne
    wrote on last edited by
    #1

    Hi, is there a description (or sample code) how to start in a form frmA a second form frmB in a thread and get access in frmA to the variables in the thread of frmB? Hope the question is clear... Thanks Andreas

    Ariadne

    M 1 Reply Last reply
    0
    • A Ariadne

      Hi, is there a description (or sample code) how to start in a form frmA a second form frmB in a thread and get access in frmA to the variables in the thread of frmB? Hope the question is clear... Thanks Andreas

      Ariadne

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Sounds like the funktionality of a Splash screen[^]! Summary:

      Ariadne wrote:

      how to start in a form frmA a second form frmB in a thread

      Thread InstanceCaller = new Thread(new ThreadStart(MySplashThreadFunc)); InstanceCaller.Start(); private static void MySplashThreadFunc() { m_instance = new SplashForm(m_imageFile, m_transColor); m_instance.TopMost = false; m_instance.ShowDialog(); }

      Ariadne wrote:

      get access in frmA to the variables in the thread of frmB

      Use delegates! Colin's article (passing values between forms)[^] If you whant to modify your GUI over an other thread: Don't forget to use InvokeRequired and Invoke! Hope it helps!

      All the best, Martin

      N 1 Reply Last reply
      0
      • M Martin 0

        Hello, Sounds like the funktionality of a Splash screen[^]! Summary:

        Ariadne wrote:

        how to start in a form frmA a second form frmB in a thread

        Thread InstanceCaller = new Thread(new ThreadStart(MySplashThreadFunc)); InstanceCaller.Start(); private static void MySplashThreadFunc() { m_instance = new SplashForm(m_imageFile, m_transColor); m_instance.TopMost = false; m_instance.ShowDialog(); }

        Ariadne wrote:

        get access in frmA to the variables in the thread of frmB

        Use delegates! Colin's article (passing values between forms)[^] If you whant to modify your GUI over an other thread: Don't forget to use InvokeRequired and Invoke! Hope it helps!

        All the best, Martin

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        As usual excellent post..:cool:


        My Website | Ask smart questions

        M 1 Reply Last reply
        0
        • N N a v a n e e t h

          As usual excellent post..:cool:


          My Website | Ask smart questions

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          :rose: Thanks a lot!

          All the best, Martin

          A 1 Reply Last reply
          0
          • M Martin 0

            :rose: Thanks a lot!

            All the best, Martin

            A Offline
            A Offline
            Ariadne
            wrote on last edited by
            #5

            Martin, thanks! It works. But unfortunatly it solves not my problem: If I debug the frmA, the timer in frmB stops also. Is there a way to exclude frmB from debugging? Or have I to use a separate application frmB and use interprocess data exchange to get the data from frmB. (frmB collects temperatures, and frmA reads them from frmB)

            Ariadne

            M 1 Reply Last reply
            0
            • A Ariadne

              Martin, thanks! It works. But unfortunatly it solves not my problem: If I debug the frmA, the timer in frmB stops also. Is there a way to exclude frmB from debugging? Or have I to use a separate application frmB and use interprocess data exchange to get the data from frmB. (frmB collects temperatures, and frmA reads them from frmB)

              Ariadne

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Hello,

              Ariadne wrote:

              If I debug the frmA, the timer in frmB stops also. Is there a way to exclude frmB from debugging?

              Hmmm, interesting task! What kind of timer are you using? Maybe take a look at System.Threading or System.Timers. Timer! But I have to admit that this is without knowing something about debug behaviour! Maybe you should start a new thread with this specific question. I'm sure the MVP cracks or for example Luc (but also others), know more about this topic. Hope it helps!

              All the best, Martin

              A 1 Reply Last reply
              0
              • M Martin 0

                Hello,

                Ariadne wrote:

                If I debug the frmA, the timer in frmB stops also. Is there a way to exclude frmB from debugging?

                Hmmm, interesting task! What kind of timer are you using? Maybe take a look at System.Threading or System.Timers. Timer! But I have to admit that this is without knowing something about debug behaviour! Maybe you should start a new thread with this specific question. I'm sure the MVP cracks or for example Luc (but also others), know more about this topic. Hope it helps!

                All the best, Martin

                A Offline
                A Offline
                Ariadne
                wrote on last edited by
                #7

                Thanks.

                Martin# wrote:

                Maybe you should start a new thread with this specific question.

                Yes I did so...

                Ariadne

                M 1 Reply Last reply
                0
                • A Ariadne

                  Thanks.

                  Martin# wrote:

                  Maybe you should start a new thread with this specific question.

                  Yes I did so...

                  Ariadne

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  Ok, But you should really, try the approach with an other timer, which is not running in the GUI thread (Forms.Timer does run in GUI thread)

                  All the best, Martin

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups