locked
Pausing the codes for 5 seconds RRS feed

  • Question

  • User-360635291 posted

    I'm running a simple test.  These are my codes:

    Image1.Visible = True
    System.Threading.Thread.Sleep(5000)
    BankImportStatusL.Text = "Done"

    Image1 is just the spinning circle telling the user it's doing something.  I just want this image to be visible and spin for 5 sec and then my Label come back with a done.

    When I click the buttong, the browser does wait the 5 sec but my image never appears with the spinning wheel.  After 5 sec, I get both the spinning wheel and the message at the same time. 

    I want the wheel first for 5 sec and then the message.

    Wednesday, December 11, 2013 1:47 PM

Answers

All replies

  • User-484054684 posted

    Basically it is the server side code you have written above three lines.

    The server sends the response back to the browser 'after processing all the code written on server side'.

    So, setting properties of image, waiting for 5 seconds, and setting text for label - all will be over - and only after that, the server sends the HTML response back to the client and so you see that behavior.

    To accomplish what you would like to do - You would need to put the spinning text before you call the server. If you are using async calls - you can first do it on your javascript and then write those three lines in your asynchronous call on server side. I don't think if there is a way for normal ASP.NET pages for this behavior in an easy manner.

    Wednesday, December 11, 2013 1:55 PM
  • User753101303 posted

    Hi,

    Keep in mind that this code runs server side. So your code runs, wait 5 s, change the label value. Then when your code ends the whole control hierarchy is rendered as an HTML page that is sent to the browser and then rendered.

    Some context could help. Do you want a general mechanism on all your pages ? Is this for an AJAX call ? etc...

    Generally this is the previous page that shows a message when you start loading the next one...

    Wednesday, December 11, 2013 1:59 PM
  • User-360635291 posted

    Thanks for the quick reply.  Basically, this is what is really going on.

    On Button click, it's telling my SQL to execute a SSIS package and then it's doing a quick test against the table to see if there are any records.  It then tells the user if there are records or no records.  The problem is that the button tells SQL to execute and then it goes straight into my test before the SSIS package can complete so it always comes back as no records even though after 5 seconds there are 100s of records.  I was trying to put a pause in between the two processes so it can complete before it runs the test.  I wanted the spinning circle just so the user knows it's doing something.  I'll take any ideas on how to better handle this process if you have any ideas.

    As for the Java - I'm a newbie and haven't really played with Java.  Can someone show me how to write a simple java script and then what I would write in OnClick to launch the Java that will launch the spinning circle?

    Anything you can do to help a newbie is greatly appreciated.

    Wednesday, December 11, 2013 2:14 PM
  • User2103319870 posted

    Hi,

    Check the below link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 11, 2013 2:22 PM
  • User281315223 posted

    You may want to consider handling this purely client-side if that is an option (or consider using an AJAX request to perform your operation) as opposed to attempting to use the Thread.Sleep() method which will simply wait for five seconds prior to actually finishing any of the code in your code behind.

    This is how your existing code would execute : 

    1. Click your Button to trigger your PostBack.
    2. You would wait for 5~ seconds while all of your code listed above executes (the Visibility, the Sleep and setting the Text)
    3. Then your page would PostBack displaying all of the changes from above.

    You should consider using the window.setTimeout() function within Javascript, which would essentially allow you to do the same thing but within Javascript : 

    Wednesday, December 11, 2013 2:51 PM