How to stop the form's current execution?

  • Thread starter Thread starter dbui
  • Start date Start date
D

dbui

I have a window application (vb.net). It opens up a form and there are 2
buttons on it. One is Exec-button and other is Stop-button.
The Exec-button will call a few functions and it uses a few global
variables. Sometimes I want to stop the current execution by clicking on the
Stop-button. However, the Click doesn't take place till after the execution
finishes. How do I achive this task?
Thanks for all input.
--bui
 
* "dbui said:
I have a window application (vb.net). It opens up a form and there are 2
buttons on it. One is Exec-button and other is Stop-button.
The Exec-button will call a few functions and it uses a few global
variables. Sometimes I want to stop the current execution by clicking on the
Stop-button. However, the Click doesn't take place till after the execution
finishes.

'System.Windows.Forms.Application.DoEvents'.

- or -

Multithreading:

<URL:http://www.devx.com/dotnet/Article/11358/>
 
Thanks for helping.
I did use System.Windows.Forms.Application.DoEvents and it didn't response
quite well. I then put the DoEvents statement in every loops in the called
routines. It improves a little bit, and it looks very messy in the code.

About multithreading, would the new created thread be able to access the
public variables declared in the form class?

--bui
 
dbui said:
Thanks for helping.
I did use System.Windows.Forms.Application.DoEvents and it didn't response
quite well. I then put the DoEvents statement in every loops in the called
routines. It improves a little bit, and it looks very messy in the code.

About multithreading, would the new created thread be able to access the
public variables declared in the form class?

That depends on how you do things. See
http://www.pobox.com/~skeet/csharp/multithreading.html#windows.forms
for more information.
 
* "dbui said:
Thanks for helping.
I did use System.Windows.Forms.Application.DoEvents and it didn't response
quite well. I then put the DoEvents statement in every loops in the called
routines. It improves a little bit, and it looks very messy in the code.

About multithreading, would the new created thread be able to access the
public variables declared in the form class?

That depends on the datatype of the variable.
 
thank you both for helping.

I just finished reading the link given by Jon. It's very helpful and I think
I've chose to use multithreading for my application. I still concern a bit
about datatype as Wagner stated in his response. I do have 2 third party
objects declared globally in my main form. Will the com-interop vars be seen
by the new thread? Is there any link that tells which data type is / isn't
accessible by the new created threads?

--bui


dbui said:
Thanks for helping.
I did use System.Windows.Forms.Application.DoEvents and it didn't response
quite well. I then put the DoEvents statement in every loops in the called
routines. It improves a little bit, and it looks very messy in the code.

About multithreading, would the new created thread be able to access the
public variables declared in the form class?

--bui

on
 
Back
Top