I would like to find out if there is a way to add a bit of time for one line of code to complete before Starting the next.
I would like my textbox to display the contents of an action as in:
case 4 TextBox1.Text = "My Text" ---Do Somehting here to slow the system down for about 5 seconds TheAmount = TheAmount - 50 If TheAmount <= 5000 Then MessageBox.Show("Your Amount is: " & TheAmount) End IfMy problem in the above is that the MessageBox shows up before the user has a chance to see what the text is.
Any Ideas
Thanks

Timing issue
Tpzguy
But by putting a thread.sleep in there you are in essence stopping the application from doing anything else - threading sleeps make the UI unresponsive for 5 seconds.
If your going to display a message because something is wrong, why wait 5 seconds to do it - its still going to display the msgbox and nothing is going to chnage in that 5 seconds with the thread sleep.
So it would appear to be somewhat of a waste of time intentionally slowing the application down.
Threading sleep will work - dont get me wrong. But I think that the fundemental reasoning behind intentionally slowing down a application may be flawed.
Marcuscoker
I think his language is the problem. He doesn't want to slow his system down. He wants a five second display period in which nothing will happen and then the message box displays.
I believe that's what he meant.
Crisdin
Yeah, I have to admit that I thought this, but like Renee, I just answered the question at hand rather than asking the deeper question that was needed here.
Sanjeev Singh
"Thread.Sleep(5000) is 5 seconds. "
I know! I thought he wanted 5 seconds.
"---Do Somehting here to slow the system down for about 5 seconds"
Spotty.... by "the system", I think he meant his program.
Antoniodya
I totally agree. I wouldn't do and I wouldn't design it that way and what you said did occur to me
BUT.......
I think this is a conversation to be had after he tries it and doesn't like it.
Evergray
As spotty has said, I think we both understood the question, he just voiced my thoughts, that the overall APPROACH in stopping his app for 5 seconds is problematic.
Vadivel_erode
System.Threading.Threads.Sleep(5000)
Gwen T
Firstly - is it essential that the textbox be reflected for every iteration of the loop or can you simply display the textbox at the end of the loop.
If you put something like Textbox1.text = i inside this loop the loop will run extremely quickly and quicker than the screen could update. So it has a concept of sending these update requests to a queue. But before it can finish the first request youve sent another to update it again.
if it was really essential to update the textbox on each iteration and show it then putting a application.doevents would help as it essentially tells the application to wait until the reuqest to update the textbox.text and any other outstanding windows request has been processed. It would significantly slow down the loop process as the loop is now dependent on the screen being updated.
But if its just the final result that matter then you can simply do the calculation in the loop and update the textbox.text immediately after the loop completes.
The general concept of putting a thread.sleep in here is not a good solution to this problem.
JudiSue
The first question is why do you want ot slow the system down here
Slowing apps down is the last thing you want to intentionally code, unless there is a damn good reason for it.
Is it that the Textbox1 test isnt displaying the text.prior to the messagebox being displayed If the textbox is displaying the appropriate text before the messagebox is displayed - then why would you intentionally want to stop the application for 5 seconds before displaying a messagebox that is going to require user interaction anyway.
.
BLiTZWiNG
I guess I mis-stated a little.
I want the text box to display before the message box comes up. I tried to put in a "For Loop" and just have the computer Loop through some calculations for a second or two then move onto the next line of code. But it seems that it (The program) does the looping at the same time as pulling up the MessageBox.
eg
For i = 0 To 3000 Step 1
Next
I used 5 seconds so that when I set the program up I would be able to see the pause and then I could easily adjust that amount down to 1 second.
Sorry about the confusion
nguyenvinhtu
So my problem remains that I would like the user to be able to see what the text box syas before the next form arrives and blocks out the information.
Dim x As Integer = 525
Dim y As Integer = 750
TextBox1.Text = "The Result is: " & x * y ' Display this before opening the next box
Form2.Show() ' is there andy way to slow this form down.
Thanks
E.Geg
kevin83
I would say that it is a possible solution, just a bad habit to get into using thread.sleep to cause applications to slow down and make UI unresponsive.
If not in this circumstance then using the same approach elsewhere can cause a much greater problem. Thread.sleep is something which can be used but really is not a good approach for many purposes.
Yes, it will solve the problem. But would I recommend it - probably not. 1 second maybe not a problem, 5 seconds maybe still not a problem.
But if I said I wanted to wait for 2 minutes would we still be recommending the thread.sleep method
James 39b
Renee, I agree with Spotty, the overall idea is flawed. But, I was answering him at the same time as you, I was not responding to/correcting you. We said the same thing.