Welcome Guest Search | Active Topics | Members | Log In | Register

Re: no response for cancel button click Options · View
Jeff Gaines
Posted: Sunday, January 06, 2008 11:27:42 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 06/01/2008 23:27:42
Date: Mon, 07 Jan 2008 07:27:42 -0800

On 07/01/2008 in message
<4f4c7678-247f-40f1-8ec1-4ee2b277a01a@i72g2000hsd.googlegroups.com>
linda.chen@faa.gov wrote:

>Our problem is: when data download starts, if a user click on the
>cancel button, it does not response. The break point inside the
>button_click event menthos is never reached. That also happens even
>when I stop the progress bar update.

I had this with an FTP client I am writing. I added an
'Application.DoEvents()' in the down-load loop. You could then use a
boolean 'abort' variable, set it when Cancel is clicked and check for it
in the down-load loop.

--
Jeff Gaines
Marc Gravell
Posted: Monday, January 07, 2008 3:10:06 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 07/01/2008 15:10:06
Date: Mon, 7 Jan 2008 15:10:06 -0000

I'm assuming that the download is happening on the UI thread; this
means that the UI cannot respond to any inputs. You should investigate
the BackgroundWorker component (lots of examples around), which will
push this work to a background thread, while still making it easy (via
the progress changed event) to update your progress-bar. Most
importantly, the UI thread will be able to service the cancel button,
and ask the BackgroundWorker to cancel (your code needs to check for
this cancellation request periodically).

Marc


Marc Gravell
Posted: Monday, January 07, 2008 3:43:22 PM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 07/01/2008 15:43:22
Date: Mon, 7 Jan 2008 15:43:22 -0000

> I added an 'Application.DoEvents()' in the down-load loop.
Just for purism... Application.DoEvents() isn't always a
good/recommended solution to this problem - you can run into all sorts
of issues with reentrancy, and other odd "trying to do 2 things on 1
thread" issues, etc. If it was me, I'd *absolutely* be using a worker
thread here.

> You could then use a boolean 'abort' variable
As a second note on the abort variable - if you went this route, you'd
probably want to make this field "volatile", otherwise it gets a bit
hit-and-miss on whether your loop will ever see the change (it could
perhaps be help on a register).

Marc


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.1 (NET v2.0) - 9/10/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.049 seconds.