|
-
Mar 22nd, 2000, 07:39 PM
#1
Thread Starter
Frenzied Member
I think your getting a little obsessive about this, by the looks of your post microsoft report the danger with DoEvents is if one message is being processed and somehow the same message is sent again during that process. If you're carefull you'll be alright, as long as your not buggering about with multi threading. when form unload is called the form won't accept any more messages to it's queue because it's not there, microsoft wouldn't put a command into the language if it makes your app unstable every time you use it.
-
Mar 22nd, 2000, 11:31 PM
#2
transcendental analytic
I suppose you're right: The risk is tiny (unless you have a loop), but if nobody knows, this problem will always occur. I want to make the code to the ultimate guarantee that doevents is safe. Still, why didn't the microsoft guys mention it?
And the qwestion remains, is there a way how to know if there are any subs or functions running?
-
Mar 22nd, 2000, 11:42 PM
#3
Member
DoEvents misuse
I agree with Sam. It takes experience to understand when to use and when NOT to use DoEvents. Microsoft doesn't say "DON'T USE IT, it's going to crash your program", they are saying "Use caution when implementing its use because 'this, and this, and that' could happen (as an example) if you aren't careful". They're in essence, letting the naive ones know that caution should be exercised.
I have used DoEvents many times in my programs and deployed them to the Fortune 500 companies and they are working just fine and (of course) caution was used WHEN to use them.
Besides, why are you using DoEvents in a heavy, continuous loop anyway? In my opinion, it is NOT to be used this way, especially if you don't want to, or need to be careful about function/sub re-entrance. If you have to, keep a counter (lngCount) for each record processed, and at every 100th or 500th record process a doevents using this code...
----------------------
' Code is simplified for example
' and not for efficiency
----------------------
Dim lngCount as long
lngCount = 0 ' Simply for clarity
Do while not rs.eof ' Not the most efficient loop with rs.eof
lngCount = lngCount + 1
if lngCount mod 100 = 0 then DoEvents
...
loop
----------------------
If you look at the last VBPJ 101 tips in about January/February, you will see a notice about handling KeyEvents and MouseEvents with an API call which can eliminate using the DoEvents each time and instead, when the Mouse or Key Events happen, you can THEN process the DoEvents. This is if you want to capture clicking on a Cancel button or getting and Esc keypress.
There are other ways to use the system, you just need to have the experience in doing it.
"Are there any Functions or Subs running?" Because VB is a system that must process a complete set of functions and subs (assuming there are no doevents calls) before returning. If I am understanding your question correctly, there can be NO functions or routines running when the unload routine is processed (except in the event of callbacks, and ActiveEXE servers processing your requests on timers) This is something YOU are going to have to manage very, very carefully.
Senior Systems Architect/Programmer
-
Mar 23rd, 2000, 02:51 AM
#4
transcendental analytic
Jaguar: "Because VB is a system that must process a complete set of functions and subs (assuming there are no doevents calls) before returning. If I am understanding your question correctly, there can be NO functions or routines running when the unload routine is processed"
There is just the doevents. When it is called, and as microsoft says, the function/sub that has it, will temporarily yield the processor under this time you are able to close the program. And when the program is supposed to be closed, it's not. It's waiting for sub/function to run complete and it never will until windows shutdown sequence will notice that the program is not responding.
About the doevents-counter in your loop: I use this as much as you do, the program will run faster that way. But there is no difference: People can still close the app, and shutdown windows.
Im not saying that "DON'T USE IT" either, almost all my apps contains doevents, and they never crash. I had once a continous loop with doevents but I never even thinked about doing something about it. I closed it always with ctrl-alt-delete and end task. Now people here can do the same thing, but the reason why I posted all this **** (as you may call it) whas that somebody, I don't know who it was, was asking for it. And this somebody had a continous loop with doevents in a module. Thats all.
People, use doevents, get
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|