About the opposite of DoEvents???
Dear VBformers,
I am working on some source code, that needs to finish before it could pass over to the next section of source code, after it, then so. Then however I am looking instead of the continue after the line has been executed into action, then i am looking at some process to wait until it has finished, before it could be able to pass over, then so...
!! Thanks in advance !!
Re: About the opposite of DoEvents???
vb6 codes runs sequentially, so if you have
- code lines
- call functions (this will need to finish before it continues)
- codes lines
if you instead call a executable or a 3rd dll, theres the waitprocess apis u can use.
Re: About the opposite of DoEvents???
I guess what i am getting is multi-threaded processes, which i guess you could call it, then so
Re: About the opposite of DoEvents???
Re: About the opposite of DoEvents???
the purpose of multi-threading is to allow different threads to work separately, otherwise theres no point of using it.
to wait for another thread to be done is useless. better to just use 1 thread.
but, for example you have 2 threads.
1 is the main program, the UI. the 2 is a processor for something.
while the 2nd is working u can allow the user to go around the UI and do things, but, theres a "button", say: (show result) that if u press, it should wait until the 2nd thread is done.
well. now, depends if you have control of the 2nd thread. u could have a communication between the 2, like a loop that is waiting until the process is done. so its not the opposite of Doevents, but actually a Doevents, a loop that will wait and only exit when process=done.
Re: About the opposite of DoEvents???
I'm not clear on why you'd jump into all the complexities of multi-threading, when you're going to wait on the second thread to finish anway. IMHO, the whole reason for multi-threading is so you can go on doing other stuff while the second thread does some heavy (time consuming) lifting.
Re: About the opposite of DoEvents???
Re: About the opposite of DoEvents???
In Adobe Director, they use the term: go to the frame, which is able to pause the playback head to that position, which is something like i need to do here, then so???
Re: About the opposite of DoEvents???
Just trying to actually answer the question, about the best I could come up with is that the opposite of DoEvents would be to "ignore the message pump" for some period of time.
With that understanding, here's what I came up with:
Code:
Option Explicit
'
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Any, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
'
Private Sub Form_Activate()
IgnoreMsgPump 10000
End Sub
Public Sub IgnoreMsgPump(ForMilliSeconds As Long) ' Opposite of DoEvents?
Dim cFreq As Currency
Dim cValue As Currency
Dim dStart As Double
Dim Msg(6) As Long
'
QueryPerformanceFrequency cFreq
QueryPerformanceCounter cValue
dStart = cValue / cFreq
Do
PeekMessage Msg(0), 0&, 0&, 0&, 1&
QueryPerformanceCounter cValue
Loop While (cValue / cFreq - dStart) < (ForMilliSeconds / 1000#)
End Sub
Now again, I'm not sure why you'd do this, but that'll do it. Also, it'd be a bit rude to actually do that, as you can't even move the form while ignoring Windows messages.
Another (similar) approach might be to ignore just keyboard and mouse input. The above could fairly easily be modified to do that by altering the range of messages tossed (third and fourth arguments of PeekMessage). And then, if you wanted to get really fancy, you could check the mouse events and make sure they applied to the client area, and, if not, pass them along.
Re: About the opposite of DoEvents???
How am i able to work it into the inflation of a binary file, like a MKV file, then so???