0

Is there a way when I click on a ToolStripButton, it shows the WaitCursor and updates the StatusStrip for about 10 seconds, then returns back to normal. I just don't know how to type in the coding.

If someone could guide me through the process. (or even give me the code)

Thank You

J Mahone

Mr Mahone
  • 27
  • 1
  • 8
  • what are you doing that takes **10 seconds**. what code have you tried? – Ňɏssa Pøngjǣrdenlarp Oct 16 '13 at 19:31
  • The coding I have tries is Me.UseWaitCursor = True ToolStripStatusLabel1.Text = "Saving, please wait" I just don't know how to get the 10 seconds bit – Mr Mahone Oct 16 '13 at 19:34
  • Why not Set the cursor (`Me.Cursor = WaitCursor`), do your thing, then set it back. No need to set on a timer. Unless you are saving the Old Testament, it generally happens fast enough that you dont need a message, especially if the user just clicked Save. – Ňɏssa Pøngjǣrdenlarp Oct 16 '13 at 19:40
  • You have a good point. But I want the application to wait for 10 seconds, you see it is not even saving anything, i just want it to do that. Is it still possible to do? – Mr Mahone Oct 16 '13 at 19:45
  • by "wait" you mean lock out the user? – Ňɏssa Pøngjǣrdenlarp Oct 16 '13 at 19:49
  • 1
    You could use a timer or a thread with a thread.sleep(10000) to do this. I think there might be a way with Lambda and async that puts is all in one method. What version of VS/Framework are you using? – Steve Oct 16 '13 at 19:51
  • Hi Steve and Plutonix, No, I just want the waitcursor to appear for 10 seconds then go back to normal and the toolstripstatuslabel to appear something diffrent, then change back to 'Ready'. – Mr Mahone Oct 16 '13 at 19:54
  • then use a timer, set the cursor to Me.Cursor = WaitCursor AND Me.WaitCursor = True. when the timer goes off, restore them both – Ňɏssa Pøngjǣrdenlarp Oct 16 '13 at 19:57
  • Hi There, Could I ask how to do that? I hardly know anything about timers on vb.net, Thanks. – Mr Mahone Oct 16 '13 at 20:22

2 Answers2

0

Using a timer:

1:Add a timer from your component toolbox to your form.

2:Set the inteval to 10,000 (this is in milliseconds, 1000 = 1 second)

3:In the timers' "Tick" event, write this code:

Timer1.stop 'This assumes your timer it named Timer1
Me.Cursor = Cursors.Default

4: When you want to make it show the cursor, either have a method to do both these lines and call the method or just write these 2 lines all over the place:

Me.Cursor = Cursors.WaitCursor
Timer1.Start
Steve
  • 5,585
  • 2
  • 18
  • 32
0

I'd suggest to use async/await to keep the "normal" program flow.

Me.Cursor = Cursors.WaitCursor
Await Task.Delay(10000)
Me.Cursor = Cursors.Default
igrimpe
  • 1,775
  • 11
  • 12