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..
AlexPonnathAsked:
Who is Participating?
 
nachiketCommented:
==================================
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);
                  mi.BeginInvoke(null,null);
            }

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

            private void stop_Click(object sender, System.EventArgs e)
            {
                  stopFlag = true;
            }
0
 
doobdaveCommented:
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.
0
 
dvsameerkumarCommented:
put a command button called abort

Private Sub abort_click()
'Close the connection
conn.close
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.