If the method Invalidate accesses some controls and it is getting invoked on a thread other then the one the controls were created on (which is what may be happening by using BeginInvoke ), then you need to invoke a method to do the updating on the original thread. You can easily check by checking the control's field InvokeRequired
For example,
if ( this.someControl.InvokeRequired )
this.someControl.Invoke( new MyDelegate( MyDelegatedMethod),args );
I have a program which use multithread.
Inadvertently dare I say, as they are not my threads but those of a FileSystemWatcher.
Anyway some method get called on my GUI.
I rewrite the code in such a way that it should only be to a funtion like that:
void HTreeChanged(object sender, TreeEventArgs e)
{
if(base.Created)
BeginInvoke(new Action(Invalidate));
}
however there is, apparently, another method call on an other thread.
the problem is I have no idea which one and VS.NET popup a message box saying:
System.InvalidOperationException was unhandled
Message: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
but even though I looked at all the active thread's stack I have no idea which method is throwing..
what can I do?
I found the problem.
Hey... this InvokeRequired variable is interesting....!!
Anyway I manage to single thread the code in my data

Signature
If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
If the method Invalidate accesses some controls and it is getting invoked on a thread other then the one the controls were created on (which is what may be happening by using BeginInvoke ), then you need to invoke a method to do the updating on the original thread. You can easily check by checking the control's field InvokeRequired
For example,
if ( this.someControl.InvokeRequired )
this.someControl.Invoke( new MyDelegate( MyDelegatedMethod),args );
"Lloyd Dupont" <ld@NewsAccount.galador.net> wrote in message news:upQcGljpFHA.3156@TK2MSFTNGP10.phx.gbl...
I have a program which use multithread.
Inadvertently dare I say, as they are not my threads but those of a FileSystemWatcher.
Anyway some method get called on my GUI.
I rewrite the code in such a way that it should only be to a funtion like that:
void HTreeChanged(object sender, TreeEventArgs e)
{
if(base.Created)
BeginInvoke(new Action(Invalidate));
}
however there is, apparently, another method call on an other thread.
the problem is I have no idea which one and VS.NET popup a message box saying:
System.InvalidOperationException was unhandled
Message: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
but even though I looked at all the active thread's stack I have no idea which method is throwing..
what can I do?
William C. - 22 Aug 2005 17:42 GMT
testing
I found the problem.
Hey... this InvokeRequired variable is interesting....!!
Anyway I manage to single thread the code in my data
--
If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"David Levine" <noSpam12dlevineNNTP2@wi.rr.com> wrote in message news:%238As3ujpFHA.420@TK2MSFTNGP09.phx.gbl...
If the method Invalidate accesses some controls and it is getting invoked on a thread other then the one the controls were created on (which is what may be happening by using BeginInvoke ), then you need to invoke a method to do the updating on the original thread. You can easily check by checking the control's field InvokeRequired
For example,
if ( this.someControl.InvokeRequired )
this.someControl.Invoke( new MyDelegate( MyDelegatedMethod),args );
"Lloyd Dupont" <ld@NewsAccount.galador.net> wrote in message news:upQcGljpFHA.3156@TK2MSFTNGP10.phx.gbl...
I have a program which use multithread.
Inadvertently dare I say, as they are not my threads but those of a FileSystemWatcher.
Anyway some method get called on my GUI.
I rewrite the code in such a way that it should only be to a funtion like that:
void HTreeChanged(object sender, TreeEventArgs e)
{
if(base.Created)
BeginInvoke(new Action(Invalidate));
}
however there is, apparently, another method call on an other thread.
the problem is I have no idea which one and VS.NET popup a message box saying:
System.InvalidOperationException was unhandled
Message: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
but even though I looked at all the active thread's stack I have no idea which method is throwing..
what can I do?