james henderson
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.W riteLine(" 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)
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.W
// 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.