Solved

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

Posted on 1998-12-19
1
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month4 days, 15 hours left to enroll

636 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