You must Sign In to post a response.
  • Category: ASP.NET

    Thread sleep is important or optional.

    Hello developers,
    If i delete a row there is a line like system.threadimg.thread.sleep(2000); this line is important or optional.
    the Row is deleting whether i give the line or not. So what is the difference with the line and without the line.
    when i did not give this line what happen while i am deleting, if anyone know explain me,
    below is my code,


    //System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('No Permission to Delete!')</SCRIPT>");
    //Label lblId = (Label)cgv.Rows[e.RowIndex].FindControl("lblID");
    //int i = objAdmin.UpdateRecord("update tbl_register set status='D' where id=" + Convert.ToInt32(lblId.Text), "T_temp");
    //if (i > 0)
    //{
    // bindgridview();
    // System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Deleted Successfully !')</SCRIPT>");
    //}
    //cgv.EditIndex = -1;
    //System.Threading.Thread.Sleep(2000);
    //bindgridview();
    }
    }


    Thanks with,
    Paul.S
  • #762365

    Hi Paul Raj,

    I hope you know the Deadlock situation, if the multiple persons did the same action against same object in that case deadlock situation will arise, to overcome that deadlock situation we are using Threading concepts, if we use that threading concept it's holds the data until that time line against user.

    Syntax:

    Threading.Sleep(milliseconds);


    In the above syntax until that milliseconds time, it holds the data.

    My suggestion is, In deleting case better to use threading concept to lock that particular table until action completed.


    Hope this will helpful to you..


    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762366

    Hi Paul.

    It is used to make the control wait for some time based on the time you specify with in that code. With out that line also you can run successfully.

    if (i > 0)
    {
    bindgridview();
    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Deleted Successfully !')</SCRIPT>");
    }
    cgv.EditIndex = -1;
    System.Threading.Thread.Sleep(2000); // here we are making the cursor or control to wait few seconds based on the time you specify.

    bindgridview();//Then it will bind the gridview, to perform the delete operation we are giving it time to maintain consistency.

    }


    Sridhar Thota.
    Editor: DNS Forum.

  • #762379
    Thanking you mr.naveen and mr.Sridhar

    Paul.S

  • #762559
    Hi

    Using the line to make thread sleep is depending up on your requirement.
    If you have situation that deadlock may occur like two operations occur at same time, then you must use thread.sleep() to avoid deadlock.

    If you are sure no other operation is going to perform then no need to use that is optional.

    Regards

    Sai Krishna Reddy.


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.