Time delay before redirect

后端 未结 2 571
栀梦
栀梦 2021-02-04 08:03

I create a register page for my web application. The application require that after user successfully register a new account, the page will show a message \"Register successfull

2条回答
  •  离开以前
    2021-02-04 08:34

    Thread.Sleep(5000) only suspends your thread for 5 seconds - no code onto this thread will be executed during this time. So no messages or anything else.

    If it's an ASP.NET app, client doesn't know what's going on on server and waits server's response for 5 seconds. You have to implement this logic manually. For example, either using JavaScript:

    setTimeout(function(){location.href = 'test.aspx';}, 5000);
    

    or by adding HTTP header:

    Response.AddHeader("REFRESH","5;URL=test.aspx");
    

    or meta tag:

    
    

    see more info.

    If it's a desktop application you could use something like timers. And never make main thread (UI Thread) hangs with something like Thread.Sleep.

提交回复
热议问题