Solved

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

Posted on 1998-12-19
1
145 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 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now