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

Posted on 2005-04-26
Last Modified: 2010-04-23
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..
Question by:AlexPonnath
    LVL 8

    Expert Comment

    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.
    LVL 4

    Accepted Solution

    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;
    LVL 1

    Expert Comment

    put a command button called abort

    Private Sub abort_click()
    'Close the connection
    End Sub

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now