Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB 'Halt Command' until Win causes an event exist?

Posted on 1998-12-19
1
Medium Priority
?
153 Views
Last Modified: 2013-12-25
Is there such a command to have my running app "halt" at a specific point in my code until windows sneds back ANY kind of event destined for my program?  The reason i ask is because i am using the "Winsock" control and noticed that i usually have to run a:

do
DoEvents
loop until Whatever=DONE

when i do this i notice that my CPU usage jumps up to 100% and NEVER drops down. I am looking for a more efficient way of controling my CPU usuage. Some of you may say just use the given winsock events ie. "Connect()" or "Close()" but i am also interested in actions like "Resolving Host", etc which are NOT an occuring event but part of the Winsock.state method which MUST be in an infinite loop to be able to tell what kind of state it is in at any one moment.
With a kind of "suspending" function i am hoping that it will reactivate my program at where it left off when an incoming winsock command does occur (specificaly "Resolving Host, etc).  
0
Comment
Question by:aniston
1 Comment
 
LVL 1

Accepted Solution

by:
jf26028 earned 40 total points
ID: 1489142
You can use the sleep api.  It completely returns controll to the operating system and makes your system idle.  


Declaration:

Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)


Useage:


While WhatEverEvent <> True
    Sleep 5
Wend

This will make the program idle for 5 milliseconds and then wake up and check the WhatEverEvent and see if it is true.  

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question