• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

How can i exit a Loop we nottom Click Event...

I have a Program which imports data into sql server DB's. The tool works fine but i would like to add an
option for the user to abort / stop the import process once he clicks on a bottom. Right now the only
way to do this is to close or kill the app ?

Any idea how this can be done..
1 Solution
What is the problem exactly?
Does your button not respond because of the import operation is in progress?

If so then the problem is to do with threading, I can provide links to a couple of very useful articles.

Please clarify your prob.
Basic guideline for the framework... it is in C# ( i did not know i am in VB.NET section;)
Let me know if u want VB.NET version of it.

            private bool stopFlag = true;

            private object[] data= null;
            private void start_Click(object sender, System.EventArgs e)
                  stopFlag = false;
                  MethodInvoker mi = new MethodInvoker(GetRecords);

            private void GetRecords()
                  object[] retArr = new object[500];
                  for (int i=0;i<500;i++)
                        if (stopFlag== true)
                              break ;
                        progress.Value +=1;
                  data= retArr;
            private object GetRecord()
                  // Simulates returning 1 record
                  // Teturn the retrived object
                  return null;

            private void stop_Click(object sender, System.EventArgs e)
                  stopFlag = true;
put a command button called abort

Private Sub abort_click()
'Close the connection
End Sub

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now