Technical Questions Technical questions on Kentico CMS Connector for Microsoft SharePoint.
Kentico CMS Connector for Microsoft SharePoint > Technical Questions > lock(object) in chsarp.net View modes: 
User avatar
Member
Member
kumar.chaudhari26-gmail - 2/22/2012 1:20:01 AM
   
lock(object) in chsarp.net

Hello every one,

I am developing a web page with asp.net csharp

i have a code which is critical .
i want only one user to access that section of code at a time.

i have used the following code

string doc_number = "";
try
{
lock (lock1)
{

doc_number = PostSalaryToSAP();

// doc_number = "";
if (doc_number.Length > 6)
{
this.Result.Text = "Posting Successful For Employee id '" + cbEmpID.SelectedItem.Text.ToString() + "' With Doc_number : " + doc_number;
this.Result.ForeColor = System.Drawing.Color.Green;
this.btnPost.Enabled = false;
this.btnDelete.Enabled = false;
}
else
{
this.Result.Text = "Posting Failed ";
this.Result.ForeColor = System.Drawing.Color.Green;
}
}
}
catch (Exception ex1)
{
Result.Text = "Posting Unsuccessful ";
Result.ForeColor = System.Drawing.Color.Green;
}

but with this code this results are not getting generated properly.

Normally

doc_number = PostSalaryToSAP(); this line adds a single record to db table.

but Using this code it adds 2 rows.

what is is the actual issue i am not able to understand please help




User avatar
Member
Member
kentico_michal - 2/28/2012 5:54:03 AM
   
RE:lock(object) in chsarp.net
Hello,

Are you using Kentico CMS? I am asking you because I am not sure how this issue is related to Kentico CMS.

Have you tried to debug the code to see why it is executed two times?


Best regards,
Michal Legen