I’m doing some code cleanup, and I came across a few instances of
System.Threading.Thread.Sleep(2000);
These are all in Button Click events.
I can’t think of any reason why this would be in production code?
Am I missing something?
EDIT —
Full Code Block (some things changed, but steps are the same) — And yes, I think it sucks the way it’s done too ha
protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
try
{
System.Threading.Thread.Sleep(2000);
string guid = Profile.Auth.GUID;
activity act = new activity();
try
{
if (checkbox.Checked)
{
add.activity(true);
}
else
{
act.AddActivity(false)
}
LoadData();
}
catch (Exception ex)
{
Response.Write(ex);
}
}
catch { }
}
A possible reason is a qick hack to make a short delay before displaying the result of something.
The problem with having a
Sleepin the user interface code is that the user interface gets unresponsive. If you want a delay like that you would use a timer control. It’s a bit more work, but the user experience is better in the end.