(vb.net) Stop a thread execution on a button click


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: (vb.net) Stop a thread execution on a button click

  1. #1
    Join Date
    Oct 2004
    Location
    Charny, Quebec, Canada
    Posts
    3

    (vb.net) Stop a thread execution on a button click

    Hi guys!
    I'm a beginner in vb.net and my first project is build to check out if the internet is up our down. To do it, I want to start a thread, on a "start button" click. Once started, the sub execute a ping on three different web site in a loop until I click the stop button. When I click the "stop button", I would like to set a public boolean to "true" to force the sub to stop looping and let it end by itself. How can I do that? By clicking a button, how can I change the value of a boolean defined in the sub of this thread?

    Thanks
    Mig

  2. #2
    Join Date
    Mar 2005
    Posts
    52
    suppose u have two buttons and one boolean variable declared.Suppose the two buttons have their click event handlers respectively.

    private System.Windows.Forms.Button Start;
    private System.Windows.Forms.Button Stop;
    boolean detect=true;

    private void Start_Click(object sender, System.EventArgs e)
    {
    while(detect){
    //do some work
    }
    }

    private void Stop_Click(object sender, System.EventArgs e)
    {
    detect=false;
    }

  3. #3
    Join Date
    May 2005
    Posts
    1
    Hey Mig,

    I was wondering if your ping routine was done and working correctly... i'm trying to do something similar but I sometimes get weird results... I took the routine from a forum, just wondering where is yours coming from or if you built it yourself.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center