Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi All,

I have a web app in which there is button click function which is executed multiple times even on single click. Its a issue of multiple threads running problem.Main thread runs first and after that 2 or 3 times code executes which gives unnecessary errors.

Please advice any solution.

Or any idea about how to allow main thread execution and stops other threads being executing.

Thanks in advance.

this is the code now tell me wat else u want..

C#
if(sFunctionToCall != "")
{
    //bReturnStatus = CallCWSFunctionNoBind(sFunctionToCall, out sCWSresponse, m_objMessageElement);
    //igupta3 Mits : 28566 To restrict duplicate requests while print checks. PageLoad() is called twice.
    if ((sFunctionToCall != "PrintChecksAdaptor.UpdateStatusForPrintedChecks") || (sFunctionToCall == "PrintChecksAdaptor.UpdateStatusForPrintedChecks" && this.hdnRequest.Value != "START"))
    {
        this.hdnRequest.Value = "START";

        bReturnStatus = CallCWS(sFunctionToCall, m_objMessageElement, out sCWSresponse, false, true);
        if (sFunctionToCall == "PrintChecksAdaptor.PostCheckDetail" || sFunctionToCall == "PrintChecksAdaptor.PostCheckSummary" || sFunctionToCall == "PrintChecksAdaptor.PostCheckSubAccount")
        {
            objTempElement = XElement.Parse(sCWSresponse);
            objTempElement = objTempElement.XPathSelectElement("./Document/PrintChecks/File");
            //TextBox txtPdfFile = (TextBox)this.Form.FindControl("File");

        byte[] pdfbytes = Convert.FromBase64String(objTempElement.Value);

        Response.Buffer = true;
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.Charset = "";
        Response.AppendHeader("Content-Encoding", "none;");
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", string.Format("attachment; filename=PrintCheck.pdf"));
        Response.AddHeader("Accept-Ranges", "bytes");
        Response.BinaryWrite(pdfbytes);
        Response.Flush();
        Response.Close();
    } // if
        //igupta3 Mits : 28566 Changes starts
        string TemError = String.Empty;
        XmlDocument usersXDocTemp = new XmlDocument();
        usersXDocTemp.LoadXml(sCWSresponse);
        if (usersXDocTemp.SelectSingleNode("//WorklossError") != null)
        {
            lblError.Visible = true;
            lblError.Text = usersXDocTemp.SelectSingleNode("//WorklossError").InnerText;
        }
        this.hdnRequest.Value = string.Empty;
        //igupta3 Mits : 28566 Changes ends
    }
} // if
Posted
Updated 27-Aug-13 22:57pm
v2
Comments
CPallini 28-Aug-13 3:16am    
Do you mean you have no control on the threads you create?
Member 8128040 28-Aug-13 3:27am    
I am not creating any threads main thread started by worker process.and others threads too.
Richard MacCutchan 28-Aug-13 3:25am    
How can anyone give a solution when we have no idea what your code is doing?
Member 8128040 28-Aug-13 3:26am    
i already told u its a simple button click function
Richard MacCutchan 28-Aug-13 3:53am    
What does that mean? How do you expect us to know what your function does without seeing the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900