(C#) Label.Text = Struct.Value (Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException)
Posted
by
Kyle
on Stack Overflow
See other posts from Stack Overflow
or by Kyle
Published on 2011-01-09T16:43:06Z
Indexed on
2011/01/09
16:53 UTC
Read the original article
Hit count: 1528
I have an app that I'm working on that polls usage from an ISP (Download quota). I've tried threading this via 'new Thread(ThreaProc)' but that didn't work, now trying an IAsyncResult based approach which does the same thing... I've got no idea on how to rectify, please help?
The need-to-know:
// Global
public delegate void AsyncPollData(ref POLLDATA pData);
// Class scope:
private POLLDATA pData;
private void UpdateUsage()
{
AsyncPollData PollDataProc = new AsyncPollData(frmMain.PollUsage);
IAsyncResult result = PollDataProc.BeginInvoke(ref pData,
new AsyncCallback(UpdateDone), PollDataProc);
}
public void UpdateDone(IAsyncResult ar)
{
AsyncPollData PollDataProc = (AsyncPollData)ar.AsyncState;
PollDataProc.EndInvoke(ref pData, ar);
// The Exception occurs here:
lblStatus.Text = pData.LastError;
}
public static void PollUsage(ref POLLDATA PData)
{
PData.LastError = "Some string";
return;
}
© Stack Overflow or respective owner