Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 83
VB6 Compile Compatibility Issue 4 115
vb6 connector to mongodb 2 122
clicking a shape in a frame array vb6 3 47
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

830 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