How to start method after another one finishes (Thread)
-
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?
-
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?
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//..
-
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//..
-
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//..
-
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?
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()--------------------------------------------------
-
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()--------------------------------------------------