|
-
Jun 21st, 2004, 08:36 PM
#1
Thread Starter
Lively Member
System.Threading.Thread.Sleep [Resolved]
After some trial and error I found some articles about using the below code to delay an action from occuring.
Code:
System.Threading.Thread.Sleep(1000)
Sure it works to delay but it from what I gather only works on Win2k and XP and it puts the system to sleep for the specified time. "Meaning that nothing else will run" while it's sleeping.
Is there a better way to get a delay between two actions taking place and allow other actions to take place too?
I'm simply trying to show one picture box, hide it and then show another picture box beside it, hide it and then show another picture box beside it.
Last edited by teamdad; Jun 22nd, 2004 at 09:31 AM.
-
Jun 21st, 2004, 09:31 PM
#2
Sleep mode
Originally posted by teamdad
Code:
System.Threading.Thread.Sleep(1000)
Sure it works to delay but it from what I gather only works on Win2k and XP...
Who said that ??
This is from MSDN Help :
Thread.Sleep Method (Int32)
Platforms Supported: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
-
Jun 21st, 2004, 10:02 PM
#3
Thread Starter
Lively Member
Point taken.....
My info must have been from a bad source. It still kills anything else from happening though from my experience. For example setting picture box 2 and picture box 3 properties to Visible/False and running the below code does not show the picture boxes going from visible to hidden, visible to hidden as it should.
Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox2.Visible = True
System.Threading.Thread.Sleep(1000)
PictureBox2.Visible = False
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = True
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = False
End Sub
I have toyed around with the timer as you had suggested in your other reply to my picture box timer thread but didn't have any luck with it either. Any suggestions using the System.Threading.Thread.Sleep method?
-
Jun 22nd, 2004, 03:47 AM
#4
Member
Hi,
i'm using this method for my thread variables.
Example:
In my mp3 Player is a 'fadein' Function.
VB Code:
Private thFader as System.Threading.Thread();
Private Sub StartFadeIN()
thFader = New System.Threading.Thread(AdressOf (FadeIn))
thFader.Start();
End Sub
Private Sub FadeIn()
do while mp3player.volume < 100
mp3player.volume += 1
thFader.Sleep(100);
end while
End Sub
(This Code is not Copy pasted, only from brain memory, it's bad )
There is no Problem, the System runs perfectly, while the thread is fading the volume.
Maybee you need another thread to start and use 'join' or something else to let the main thread wait for the other thread.
-
Jun 22nd, 2004, 06:54 AM
#5
PowerPoster
Originally posted by teamdad
Point taken.....
My info must have been from a bad source. It still kills anything else from happening though from my experience. For example setting picture box 2 and picture box 3 properties to Visible/False and running the below code does not show the picture boxes going from visible to hidden, visible to hidden as it should.
Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox2.Visible = True
System.Threading.Thread.Sleep(1000)
PictureBox2.Visible = False
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = True
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = False
End Sub
I have toyed around with the timer as you had suggested in your other reply to my picture box timer thread but didn't have any luck with it either. Any suggestions using the System.Threading.Thread.Sleep method?
I find that when using Thread.Sleep as a program delay mechanism, you have to update the relevent object before using Sleep.
PictureBox2.Visible = True
PictureBox2.Update
System.Threading.Thread.Sleep(1000)
PictureBox2.Visible = False
PictureBox2.Update
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = True
PictureBox3.Update
System.Threading.Thread.Sleep(1000)
PictureBox3.Visible = False
You can also use the DateTime functions:
VB Code:
PictureBox2.Visible = True
Delay5(5)
PictureBox2.Visible = False
Delay5(6)
PictureBox3.Visible = True
Delay5(7)
PictureBox3.Visible = False
Public Sub Delay5(iDelay As Integer)
Dim dt1 As DateTime=now
Do
If Now > dt1.AddSeconds(iDelay) Then Exit Do
Loop
End Sub
Last edited by taxes; Jun 22nd, 2004 at 01:19 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 22nd, 2004, 09:30 AM
#6
Thread Starter
Lively Member
I am so thankfull that there are a bunch of people all over the world that can get along and help eachother code in peace.
-
Jun 22nd, 2004, 11:09 AM
#7
PowerPoster
Originally posted by teamdad
I am so thankfull that there are a bunch of people all over the world that can get along and help eachother code in peace.
Watch the threads!! Gets a bit heated sometimes but it never comes to blows (and we usually end up realising we are all human )
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 22nd, 2004, 01:03 PM
#8
PowerPoster
Hi teamdad,
I've just noticed my suggested code for using DateTime did not reset the variable. I have edited that post accordingly and it now allow you to choose a variable delay period.
By the way, when you find some suggested code works (or does not work) it helps if you make a reference to the posting which contained that code. Otherwise we are not sure of the code to which you refer.
Last edited by taxes; Jun 22nd, 2004 at 01:22 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|