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
  1. Home
  2. General Programming
  3. C#
  4. How to start method after another one finishes (Thread)

How to start method after another one finishes (Thread)

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
6 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.
  • C Offline
    C Offline
    choopie
    wrote on last edited by
    #1

    Hello fellows. I need your help. I have a Windows.Forms application which makes a connection to a database about 5 - 10 seconds. While I'm trying to connect to the database, an animated control starts an animation . After the connection is made I stop the animation and want to run another function to fill a DataGrid control. private void OpenConFunction() { //... some code } private void AfterConnFunction() { //... some code to fill DataGrid control } private void myButton_Click(object sender, System.EventArgs e) { Thread t = new Thread(new ThreadStart(OpenConFunction)); t.Start(); this.AnimatedControl.Start(); //Suppose AnimatedControl //has two methods one to start animation and a second one to stop it } What has to be the code after OpenConFunction returns? I want to invoke the AfterConnFunction and stop the AnimatedControl animation?

    K B 2 Replies Last reply
    0
    • C choopie

      Hello fellows. I need your help. I have a Windows.Forms application which makes a connection to a database about 5 - 10 seconds. While I'm trying to connect to the database, an animated control starts an animation . After the connection is made I stop the animation and want to run another function to fill a DataGrid control. private void OpenConFunction() { //... some code } private void AfterConnFunction() { //... some code to fill DataGrid control } private void myButton_Click(object sender, System.EventArgs e) { Thread t = new Thread(new ThreadStart(OpenConFunction)); t.Start(); this.AnimatedControl.Start(); //Suppose AnimatedControl //has two methods one to start animation and a second one to stop it } What has to be the code after OpenConFunction returns? I want to invoke the AfterConnFunction and stop the AnimatedControl animation?

      K Offline
      K Offline
      karam chandrabose
      wrote on last edited by
      #2

      i would recommend u a simplest way... call the animation method asynchronously , inside which u have following code { this.AnimatedControl.start(); while(!bnFinishedFlag) { //do nothing //bnFinished flag is class level var and will be set to true when db //operation finishes } this.AnimatedControl.stop(); //end the async method call.. } hope this helps//..

      C 2 Replies Last reply
      0
      • K karam chandrabose

        i would recommend u a simplest way... call the animation method asynchronously , inside which u have following code { this.AnimatedControl.start(); while(!bnFinishedFlag) { //do nothing //bnFinished flag is class level var and will be set to true when db //operation finishes } this.AnimatedControl.stop(); //end the async method call.. } hope this helps//..

        C Offline
        C Offline
        choopie
        wrote on last edited by
        #3

        Thanks for the reply. Unfortunately, your suggestion didn't help me. I think I need to call the OpenConFunction() in a separate thread. But I don't know how to start the AfterConnFunction when OpenConFunction ends.

        1 Reply Last reply
        0
        • K karam chandrabose

          i would recommend u a simplest way... call the animation method asynchronously , inside which u have following code { this.AnimatedControl.start(); while(!bnFinishedFlag) { //do nothing //bnFinished flag is class level var and will be set to true when db //operation finishes } this.AnimatedControl.stop(); //end the async method call.. } hope this helps//..

          C Offline
          C Offline
          choopie
          wrote on last edited by
          #4

          I mean when I start the OpenConnFunction() in a separate thread the animation starts otherwise not :(

          1 Reply Last reply
          0
          • C choopie

            Hello fellows. I need your help. I have a Windows.Forms application which makes a connection to a database about 5 - 10 seconds. While I'm trying to connect to the database, an animated control starts an animation . After the connection is made I stop the animation and want to run another function to fill a DataGrid control. private void OpenConFunction() { //... some code } private void AfterConnFunction() { //... some code to fill DataGrid control } private void myButton_Click(object sender, System.EventArgs e) { Thread t = new Thread(new ThreadStart(OpenConFunction)); t.Start(); this.AnimatedControl.Start(); //Suppose AnimatedControl //has two methods one to start animation and a second one to stop it } What has to be the code after OpenConFunction returns? I want to invoke the AfterConnFunction and stop the AnimatedControl animation?

            B Offline
            B Offline
            Bijesh
            wrote on last edited by
            #5

            You can do this using Invoke and delegates. In your OpenConFunction method, once you are done openig the connection you can do an this.BeginInvoke( new AfterConnFunctionDelegate( AfterConnFunction) ) where AfterConnFunctionDelegate is declared as a delegate with the same type as AfterConnFunction. public delegate void AfterConnFunctionDelegate(); In the AfterConnFunction method you can safely call this.AnimatedControl.Stop()

            --------------------------------------------------

            C 1 Reply Last reply
            0
            • B Bijesh

              You can do this using Invoke and delegates. In your OpenConFunction method, once you are done openig the connection you can do an this.BeginInvoke( new AfterConnFunctionDelegate( AfterConnFunction) ) where AfterConnFunctionDelegate is declared as a delegate with the same type as AfterConnFunction. public delegate void AfterConnFunctionDelegate(); In the AfterConnFunction method you can safely call this.AnimatedControl.Stop()

              --------------------------------------------------

              C Offline
              C Offline
              choopie
              wrote on last edited by
              #6

              Brilliant!! Thank you :)

              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