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);

Re: Threading help with Invoke by John

John
Fri Sep 12 16:43:40 CDT 2003

"Edward J. Stembler" <ejstembler@hotmail.com> wrote in message
news:04c501c3796b$a07883a0$a101280a@phx.gbl...
> 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?

You need to use Control.Invoke to access a control from another thread.
--
John Saunders
Internet Engineer
john.saunders@surfcontrol.com



Re: Threading help with Invoke by gilbertw

gilbertw
Fri Sep 12 18:57:54 CDT 2003

Here is a helpful doc on this topic...


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms06112002.asp

_Rick
--------------------
| From: "John Saunders" <john.saunders@surfcontrol.com>
| References: <04c501c3796b$a07883a0$a101280a@phx.gbl>
| Subject: Re: Threading help with Invoke
| Date: Fri, 12 Sep 2003 17:43:40 -0400
| Lines: 17
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uPLyybXeDHA.1700@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework
| NNTP-Posting-Host: pool-151-199-57-229.bos.east.verizon.net 151.199.57.229
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:53604
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| "Edward J. Stembler" <ejstembler@hotmail.com> wrote in message
| news:04c501c3796b$a07883a0$a101280a@phx.gbl...
| > 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?
|
| You need to use Control.Invoke to access a control from another thread.
| --
| John Saunders
| Internet Engineer
| john.saunders@surfcontrol.com
|
|
|