Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process priority or pausing event loops 4

Status
Not open for further replies.

duffman82

Programmer
Joined
Jun 27, 2005
Messages
8
Location
US
i have a code that takes code from a textbox and line by line adds each line to a listbox, the problem i run into is that if your running the command it freezes the whole program until it is complete. i want to create a pause button on the form but the program thread priority is so high that all other events on the form are obsolete. so i cannot click the pause button.

i am used to visual basic 6 where i can put a simple
pause(.05) in the loop function to prevent the process from simply locking out other user events on the form.

is there a way to do this in vb.net?
 
At the moment I'm only using this for DTS, so when the user presses the Cancel button, I set a global CancelRequested variable to true and get the DTS's OnQueryCancel Event to check the variable. If its true it returns Cancel to DTS which then finshes the transformation or whatever it is currently doing and then fires its Finish Event which allows the thread die a natural death.

This however, will be something that would need attention in most other circumstances, and since after tonight's conversations I'm feeling rather more confident about threads, I'm definitately going to be investigating this next week. So hopefully we can compare notes then.
 
With good cleanup in the Finally block, I get a fast response to the user's cancel request, and no memory leaks. But I've seen "iffy" reviews of using this method. Any opinions?
I think it's because people don't always put good cleanup code in their finally block, leaving unmanaged objects dangling.

What I've seen a lot of people do is use the Interlocked class with either the Decrement or Increment (depending on how you want to structure things) methods. This acts as a semaphore, and in your thread you would periodically check to see if it had reached zero. You would think that a simple boolean would handle this, but if you look at the generated IL code for it, there's a hole there where another thread could jump in.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top