Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is it possible to delay for less than a second?

Posted on 2011-02-12
5
Medium Priority
?
416 Views
Last Modified: 2012-05-11
Hi

I am using the following delay Sub to hold my program slightly each time it loops to write a record to multiple locations to give the program time to keep up and update certain viewable fields and a Progress Bar, but i was wondering if it is possible to delay for less than a second? As the second i feel is too long for what it required.

 
Public Sub Delay(ByVal dblSecs As Double)

        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date
        Now.AddSeconds(OneSec)
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop

    End Sub

Open in new window

0
Comment
Question by:STP_Martin24
[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
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34879042
Please show the code where you use your Delay sub. Most program statements are blocking, meaning that it does not return executing in the current function until it has returned from the call. Your GUI will not update until after the current function is complete or you place a Application.DoEvents() to pause and update the GUI.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34879062
Instead of AddSeconds(), use AddMilliseconds():
 
Public Sub Delay(ByVal intMilliseconds As Integer)
        Dim dt As DateTime = DateTime.Now.AddMilliseconds(intMilliseconds)
        Do Until Now > dt
            Application.DoEvents() ' Allow windows messages to be processed
            System.Threading.Thread.Sleep(50)
        Loop
    End Sub

Open in new window

0
 

Author Comment

by:STP_Martin24
ID: 34879063
Hi

I tried using:

System.Threading.Thread.Sleep(500)

But it did make the program any quickier comapred to Delay(1) - 1 second

Without any Delay's the program does keep up and refreshing the DTable after each new record but after a few it goes to "Not Responding" then the next update is when the program is finished writing but i just wanted to slow it down after each record so it doesn't seem to the user it isn't working if though it is. But like i said i tried the above which should be 500ms and i but a start and end time stamps and there was very little difference and the Delay(1) kept the program moving.

If anyone has anything i'm missing please post and i will be happy to look.
0
 

Author Closing Comment

by:STP_Martin24
ID: 34879088
Well that was unlucky timing as i was writing my last post as you posted yours Idle_Mind, just gave it a quick try and it looks like it works quite nice as it cut 60 record write time from 1min 30ish to about 1 minute, with the DTable Update and Progress Bar Updates working nicely.

Thanks for your quick response
0
 
LVL 3

Expert Comment

by:pasolo
ID: 34879089

If you are doing it all in a single thread you don't need more that a single Application.DoEvents() to dispatch all pending messages in the queue and update the controls (more doevents will not help because nothing else is done than dispatch messages). If you are working with a second thread for the background work then use threading.thread.sleep on that thread after each record reading.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

704 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