Pause on a line of code for a few seconds (delay) before moving on to next code in C #?

I would like to display a message for a few seconds before moving on to execute the following code. How can I do this in C #?

page load ()....
{
    label1.text="Thank you for your input";
    Delay by 3 seconds??? before entering codeX
    codeX....
    code....
}

      

Is it as easy as using wait(3000)

?

To clarify my question: I am creating a poll web part in sharepoint and would like to display a "Thank you for your vote" message for 3 seconds before submitting the poll results. I'm guessing I can use a timer inside the AJAX refresh bar so it doesn't affect the rest of the page? Hope this clarifies my question. Please let me know the best way to implement this. Thanks to

+3


source to share


3 answers


Use Javascript to show and hide your message.

<script type="text/javascript">
   $(document).ready(function () {
       $(".message").show();
       $(".message").delay(5000);
       $(".message").fadeOut(2000);
   });
</script>

      

with a div in your page:



<div class="message">Thanks for your input</div>

      

it could be in your redirected page. Or you can call a function in the curernt page if you are not redirecting, in which case you will need to change the prepared call to your own call.

+2


source


You don't want to do what you see fit. Not only this; what you want to do doesn't do what you think it does.

Server handler threads are a finite resource. You should never purposefully keep them waiting. You should also never purposefully make the user wait.

However, doing what you ask will not do what you think it will do anyway. This will hold the entire page for three seconds - it won't just display one thing and wait to display the rest.




Instead, you are most likely looking for a page refresh via AJAX, 3 seconds after the page has loaded. This will be triggered by the javascript client. We will need to know more about what you are trying to do to point you in the best direction.

+5


source


Thread.Sleep (number of milliseconds) server side

or client side

SetTimeout (1250);

0


source







All Articles