Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

757 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

20 Experts available now in Live!

Get 1:1 Help Now