473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Sleep command problem

4
Hi all,
First post!
Learning vb.net

the following is the button handler code:

TextBox1.text = "Sleeping"
Thread.Sleep(500)
TextBox1.text = "Done!"

Why is the first line being ignored?

TextBox stays empty until after Sleep() then shows "Done" message...

Thanks for any help!
May 3 '08 #1
5 1270
misza
13
Hi all,
First post!
Learning vb.net

the following is the button handler code:

TextBox1.text = "Sleeping"
Thread.Sleep(500)
TextBox1.text = "Done!"

Why is the first line being ignored?

TextBox stays empty until after Sleep() then shows "Done" message...

Thanks for any help!
Hi,

Try calling Application.DoEvents before the sleep line.

The answer to "why": for my (limited still) knowledge, it would have something to do with form events (paint, etc) - the real time they're being executed; pls someone elaborate on this;)

hope this helps
M.
May 5 '08 #2
MACH4
4
Hi M,

Thanks for replying!
Yes your additional line does work thanks!

Must admit I haven't used the Sleep command much before and my default language is Assembler, which prompted me to check it out further in that language.

It seems that Do.Events (in this particular case) is equivalent to the UpdateWindow api function call. Using InvalidateRect to force a re-paint didn't work...

MACH4
May 5 '08 #3
MACH4
4
Hi M,

Just to qualify my last message statement, I've just concocted the following code using the win32 api "UpdateWindow"...

Declare Auto Function UpdateWindow Lib "user32"(ByVal hwnd As IntPtr) As IntPtr


' Button handler code

Dim ptr As IntPtr = Handle

TextBox1.Text = "Waiting"
UpdateWindow(ptr)
Thread.Sleep(500)
TextBox1.Text = "Done!"

As you can see, its a bit clumbersome for a VB.NET application but seems explain (at least partially) what Do.Events is performing!

Thanks!

MACH4
May 5 '08 #4
Plater
7,872 Expert 4TB
do events just tells the program to process the windows messages before continuing execution.
Telling your textbox to .Update() would accomplish the text being updated as well.
May 5 '08 #5
MACH4
4
Hi Plater,

Yes, thanks or the info! I'm guilty of looking too deep!

One thing that is becoming obvious with .NET is that if some code is more than 5 lines long, then there must exist an easier way! lol

MACH4
May 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Subhakar Burri | last post by:
------_=_NextPart_001_01C3555C.697B5893 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Is there a 'sleep' command in mysql? I'm trying to...
1
by: john | last post by:
I am trying to set up a shtml page that will take 10 seconds for it to load to slow down some annoying spiders I have on my website. The shtml looks like below: <html> <head> <title>You are...
5
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
2
by: bokiteam | last post by:
Hi All, I am new to vb.net. I saw a command Thread.Sleep(1) My problem is:
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: Susan | last post by:
On our production server, we have a great deal of data. To improve performance, we give the user a "page" of data at a time and then spawn count of the total number of products based on the query...
21
by: JackCoke | last post by:
Hello. I am new at this so forgive me if there is a simple answer, although it is one I could not find. My VB 2003 program can scan a folder, determine the size of the file it finds, wait 30...
19
by: John | last post by:
The table below shows the execution time for this code snippet as measured by the unix command `time': for i in range(1000): time.sleep(inter) inter execution time ideal 0 ...
1
by: Arun Srinivasan | last post by:
Just want to know if there is a sleep command I could use to slow down the process in a stored procedure. I know people would've asked this question. I googled it, but everyone said that they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.