Click here to Skip to main content
14,382,476 members
Rate this:
Please Sign up or sign in to vote.
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..

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 23: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?
Member 8128040 28-Aug-13 4:47am
   
inside there is a simple db call and after that controls binds with data.there is no problem inside that function.
Richard MacCutchan 28-Aug-13 4:51am
   
Posting vague statements instead of showing the code that is failing is of no use whatsoever. You need to learn how to explain your problem in proper detail. We cannot read your mind or see your screen.
Member 8128040 28-Aug-13 4:55am
   
this is the code now tell me wat else u want..

[edit]Code moved to OP's question[/edit]

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100