Anyone know the VC version of VB's DoEvent()? PART 2
I am using windows. I am writing a dll for a VB app and my function is stopping the VB app so it can''t update it''s interface at all. This is why I need to find a way to give some of the CPU up...a long run time in my function makes a user think it''s frozen...Any ideas how to do this?
"Victims...aren't we all?" -Brandon Lee, the Crow
I''ll make this suggestion again. Use multithreading. That''s probably the best way to accomplish what you''re trying to do. Check out the tutorials/articles that the Anon supplied in the other thread.
Programming Windows by Charles Petzold has a chapter on multithreading too.
Programming Windows by Charles Petzold has a chapter on multithreading too.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
This works for me.........
//#################################################
void DoEvents(void)
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Sleep(0);
}
//#################################################
//#################################################
void DoEvents(void)
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Sleep(0);
}
//#################################################
February 09, 2001 06:42 AM
I am curious as to why you have a Sleep(0) statement in your function? What is its purpose?
-Z
Sleep(0) gives up the process''s
time slice..... and lets other
processes get some CPU time.
I have however read somewhere that
you need at least Sleep(10) to do
that.
time slice..... and lets other
processes get some CPU time.
I have however read somewhere that
you need at least Sleep(10) to do
that.
By default Windows dishes out CPU time in 10ms blocks (it can be changed on NT systems)
If you''re thread hits a wait (a Sleep or a WaitOnXXXX or a file block, etc...) you get swapped out and other threads get to use the remainder of ''your'' time slice.
A Sleep(0) gives up you''re time slice but places you''re thread right back in contention for the time. (ie a Time Critical/Time Critical Thread calling Sleep(0) will yeild time to itself )
Under special conditions a Sleep(0) can increase the performance your you''re thread, though general it decreases the performance your your thread in favor of greater responsiveness from the application.
A Sleep(10) means you won''t see the cpu again for at least 10ms.
Magmai Kai Holmlor
- The disgruntled & disillusioned
If you''re thread hits a wait (a Sleep or a WaitOnXXXX or a file block, etc...) you get swapped out and other threads get to use the remainder of ''your'' time slice.
A Sleep(0) gives up you''re time slice but places you''re thread right back in contention for the time. (ie a Time Critical/Time Critical Thread calling Sleep(0) will yeild time to itself )
Under special conditions a Sleep(0) can increase the performance your you''re thread, though general it decreases the performance your your thread in favor of greater responsiveness from the application.
A Sleep(10) means you won''t see the cpu again for at least 10ms.
Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement