E
Edward J. Stembler
I created a call-back Thread class and am getting an
Invoke error in the call-back method. The call-back
method access a control on the main thread. I understand
why the error is occurring, however, I don't know the
(Invoke?) syntax for correct it. I've played around with
MethodInvoke but cannot seem to get it to work. Has
anyone done something similar?
Here's a generic version of my code:
The call-back found in a Form:
private void worker_DataSetRetrieved(object sender,
DataSetRetrievedEventArgs e)
{
populateTreeView(e.DataSet);
}
The thread class et. al.:
internal class RequestQueueDataSetRetrieverThread
{
public event DataSetRetrievedHandler
DataSetRetrieved = null;
private string _user = "";
public RequestQueueDataSetRetrieverThread()
{
_user = Common.CurrentUser;
}
public RequestQueueDataSetRetrieverThread(string
user)
{
_user = user;
}
public void Start()
{
if (DataSetRetrieved == null)
return;
DataSet dataSet = getMyDataSet(_user);
DataSetRetrieved(this, new
DataSetRetrievedEventArgs(dataSet));
}
}
internal class DataSetRetrievedEventArgs: EventArgs
{
private DataSet _dataSet;
public DataSetRetrievedEventArgs(DataSet dataSet)
{
_dataSet = dataSet;
}
public DataSet DataSet
{
get
{
return _dataSet;
}
}
}
internal delegate void DataSetRetrievedHandler(object
sender, DataSetRetrievedEventArgs e);
Invoke error in the call-back method. The call-back
method access a control on the main thread. I understand
why the error is occurring, however, I don't know the
(Invoke?) syntax for correct it. I've played around with
MethodInvoke but cannot seem to get it to work. Has
anyone done something similar?
Here's a generic version of my code:
The call-back found in a Form:
private void worker_DataSetRetrieved(object sender,
DataSetRetrievedEventArgs e)
{
populateTreeView(e.DataSet);
}
The thread class et. al.:
internal class RequestQueueDataSetRetrieverThread
{
public event DataSetRetrievedHandler
DataSetRetrieved = null;
private string _user = "";
public RequestQueueDataSetRetrieverThread()
{
_user = Common.CurrentUser;
}
public RequestQueueDataSetRetrieverThread(string
user)
{
_user = user;
}
public void Start()
{
if (DataSetRetrieved == null)
return;
DataSet dataSet = getMyDataSet(_user);
DataSetRetrieved(this, new
DataSetRetrievedEventArgs(dataSet));
}
}
internal class DataSetRetrievedEventArgs: EventArgs
{
private DataSet _dataSet;
public DataSetRetrievedEventArgs(DataSet dataSet)
{
_dataSet = dataSet;
}
public DataSet DataSet
{
get
{
return _dataSet;
}
}
}
internal delegate void DataSetRetrievedHandler(object
sender, DataSetRetrievedEventArgs e);