Link to home
Start Free TrialLog in
Avatar of james henderson
james hendersonFlag for United States of America

asked on

c# event throws cross-thread error

I have created a com dll in c# that includes events.  I have referenced it in my windows form application and
can call the exposed methods and get the results I expect without a problem.  The issue is with events.

The dll runs a thread that checks a website for updated information .. it will raise an event when the
information has changed.  I have included the event in my windows form and the event is raised correctly,
but when I try to update the textbox on the form I'm getting a cross thread exception:

protected void OnStateChanged(string eventData)
{
   // this part works perfectly!
   System.Diagnostics.Debug.WriteLine("eventdata: " + eventData);
   
   // this line throws the cross-thread error.
   textBox1.text = eventData;
}

how can I get around this?  (I am using vs2012 and .net 4.5)
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of james henderson

ASKER

Thanks, Kyle! That was the step I was missing and you get the points.

As a follow up, is there a way to do the invoke step inside the dll?  The reason I ask is because the next step is to invoke this on a web page, using vbscript as the event method.