[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

richtext.text {"Cross-thread operation not valid: Control 'txtWeeklyMarketCommentary' accessed from a thread other than the thread it was created on."}

Im getting the error"Cross-thread operation not valid: Control 'txtWeeklyMarketCommentary' accessed from a thread other than the thread it was created on"

When trying to get the text from a richtextbox control does anyone no of another way i can  get this ???  
public object RunEBUSave()
        {
            if (MKIPlugin.Instance.ServerAvailable)
            {
                PCBBSupportService svc = new PCBBSupportService(MKIPlugin.Instance.Communication);
 
                if (marketInfochanged)
                {
                    MarketInformation marketInfo = new MarketInformation
                                                       {
                                                           InfoText = this.txtWeeklyMarketCommentary.Text,
                                                           XmlPostDateTime =
                                                               DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                                                       };
                    svc.PutBulletin(MKIBulletinTypes.MARKETINFO_ID, "BULLETIN", "Market Information",
                                    Encoding.UTF8.GetBytes(marketInfo.GetXmlString()));
 
                    lastUpdatedForEBU = DateTime.Now;
                }
                if (productInfoChanged)
                {
                    ProductInformation productInfo = new ProductInformation();
                    productInfo.InfoText = txtProductInformation.Text;
                    productInfo.XmlPostDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    svc.PutBulletin(MKIBulletinTypes.PRODUCTINFO_ID, "BULLETIN", "Product Information",
                                    Encoding.UTF8.GetBytes(productInfo.GetXmlString()));
 
                    lastUpdatedForEBU = DateTime.Now;
                }
 
                MKIPlugin.Instance.CommsController.DoPluginCommsProcess(
                    MKIPlugin.Instance.Communication.GetSession(false));
            }
            return null;
        }

Open in new window

0
rourkas1
Asked:
rourkas1
  • 2
1 Solution
 
drypzCommented:
Hi! In your page load event, declare this.

this.CheckForIllegalCrossThreadCalls = False;
0
 
CebikCommented:
Add this.. and use this methode..

public delegate void UpdateTxtWeeklyMarketCommentaryCallback(string s);
public void UpdateTxtWeeklyMarketCommentary(string s)
{
    if (txtWeeklyMarketCommentary.InvokeRequired)
    {
        txtWeeklyMarketCommentary.Invoke(new UpdateTxtWeeklyMarketCommentaryCallback(this.UpdateTxtWeeklyMarketCommentary), s);
    }
    else
    {
        txtWeeklyMarketCommentary.Text = s;
        txtWeeklyMarketCommentary.Refresh();
    }
}

Open in new window

0
 
CebikCommented:
Upss.. it's ASP.. but U can try
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now