How to receive the click event when running very long procedure?

  • Thread starter Thread starter Mrkrich
  • Start date Start date
M

Mrkrich

I have one procedure that will take very long time before
it finishs. During its running, I provide users a button
to cancel this process if they don't want it to run
anymore.
I have one varible for process status if user click the
cancel button this variable will change to False and the
procedure will check this variable during it run

The problem is I don't know how the program receive the
button's event during this procedure running.
 
There is a function called DoEvents in VB 6.0. But in VB.NET its
System.Windows.Forms.Application.DoEvents. SO place this function in side
your procedure
so that you can get access to the click event of the command button while
you are inside the long procedure.

Mr Utkal Ranjan, New Delhi.
 
Not sure if that's the best course of action. In order for DoEvents to
accomplish what he wants, you'd need to constanly fire it which would cause
things to slow thereby exacerbating the problem.
 
Threading will be the best way. DoEvents really pushes
control to the Messages Loop and can lead to concurrency
problems.

Run the long runnin procedure in a thread and the UI will
still be responsive and you can track the click event.

Regards,
Anand
VB.NET MVP
http://manand.typepad.com
 
Hi Mrkrich,

The most simple method for doing this is using applications.doevents in a
loop like this.
(roughly typed)

\\\\
do while fuction_is_not_ended
threading.tread.sleep(500) ' 1/2 second
application.doevents
loop
////

Cor
 
Back
Top