Getting Crooss Thread Exception on updating label....

Posted on 2011-04-26
Last Modified: 2012-05-11
hi iam Getting Crooss Thread Exception on updating happen when value changes on label....i have to create delegate event but somewhere iam stucked and icant figure out how to fix this... :? :(
private void ResetClientControll()
            myOperator.CurrentMode = OperatorMode.Client;

            ClientInformation cliInfo = AmEngine.GetEngagementInformation(myOperator).GetClientInformation(new ClientId(myOperator.CurrentClient_ID));

            LabelSelectedClient = cliInfo.ClientName;
            LabelTotalOpenTransactions = cliInfo.CountOpenTransactions;  GETTING EXCEPTION ON THIS LINE::::::::::

            decimal diff= 0;
            decimal cliInfDiff = cliInfo.Diff;
            if (cliInfDiff != (decimal)diff)
                lblTotalDifference.Visible = true;
                lblTotDiff.Visible = true;
                LabelTotalDifference = cliInfDiff;
                lblTotalDifference.Visible = false;
                lblTotDiff.Visible = false;

The label is a Long...

public long LabelTotalOpenTransactions
                return Convert.ToInt32(lblTotalOpenTran.Text);
                lblTotalOpenTran.Text = Convert.ToInt32(value).ToString(); 

Open in new window

Question by:Adnan
    LVL 4

    Expert Comment

    you are getting this exception becuase you are accessing label which UI thread owns from another thread. So you will need to make thread safe call as described here
    LVL 11

    Accepted Solution

    Hi, as already suggested, you are trying to access and modify properties of a control/UI from a thread which is not the UI thread.

    There is a "generic" solution that remove the need to define lots of type of delegates for updating the UI.

    Have the following code in the form:

            private void updateUI(MethodInvoker mi)
                if (this.InvokeRequired)

    And when you are calling ResetClientControll(), call it this way:

    MethodInvoker mi = delegate()


    This will cause the whole ResetClientControll() to be called using the UI thread.

    Author Comment

    Oki..i will try your code to see if it works but i resolved it this way code below...
    delegate void SetSensorValueDelegate(long value);
            private void SetSensorValue(long value)
                if (lblTotalOpenTran.InvokeRequired)
                    SetSensorValueDelegate del = new SetSensorValueDelegate(SetSensorValue);
                    lblTotalOpenTran.Invoke(del, new object[] { value });
                    LabelTotalOpenTransactions = value;

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now