using delay in vb.net

  • Thread starter Thread starter AmitTrehan
  • Start date Start date
A

AmitTrehan

hi friends,
I want to know how can we insert delay in vb.net
like.....
i want to show two strings on same label
first one string then break of 5 secs and then second string
how can i acheive this?
i mean label should show first
label.text("before")
then it should wait for 5 secs and then it should show
label.text("After")

thanks
Amit
 
AmitTrehan said:
hi friends,
I want to know how can we insert delay in vb.net
like.....
i want to show two strings on same label
first one string then break of 5 secs and then second string
how can i acheive this?
i mean label should show first
label.text("before")
then it should wait for 5 secs and then it should show
label.text("After")

label.text = "before"
system.threading.thread.sleep(5000)
label.text = "after"

Note that the app is locked during the 5 sec. If you don't want this, you
can use a Timer (see System.Windows.Forms.Timer) instead. After setting the
label the first time, enable the timer (interval = 5000). In the Timer's
Tick event, disable the timer and set the label text again.
 
Hi Amit,

Have a look at timer,
there are 3 can use the most simple for this the forms.form.timer

Although if you do not mind that your form freze you can also do
Roughly written here in this message
\\\
dim a as string() = {"Before","Middle","After"}
for i as integer = 0 to a.lenght - 1
label1.text = a(i)
threading.thread.sleep(5000)
next
///
I hope this helps

Cor
 
Hi Armin,

I think I get comments from Armin with my solution,

"Why not using a timer?

are you making the same

:-)

Cor
 
* "Cor said:
Have a look at timer,
there are 3 can use the most simple for this the forms.form.timer

Although if you do not mind that your form freze you can also do
Roughly written here in this message

You can make a loop looping from 1 to 5 and let the thread sleep for 1
second, then call 'Application.DoEvents'. Quick and dirty, I know.
 
Hi Herfried,

That is my own solution in past often told not to be good by you

:-) again the whole day gone?

Cor
 
Hi Amrin can't we have more genearl one that can show about 100 strings on a
specified gap

Thanks
Amit
 
AmitTrehan said:
Hi Amrin can't we have more genearl one that can show about 100
strings on a specified gap

At class level, store the information on what string to show next. In the
Timer's Tick event:
1. Use the information to show the string.
2. Change the information (an Index in a string array? Depends on your
needs) in order to show the right string next time. For example, increment
the index.
 
Back
Top