(C#) Label.Text = Struct.Value (Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException)
- by Kyle
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;
}