Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

multithread debuging

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 21 Aug 2005 11:15 GMT
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?
Lloyd Dupont - 21 Aug 2005 11:22 GMT
oopss... found it.
in the menu debug/exception you've got a little check box to throw and stop at exception!
so handy!

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.

 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?
David Levine - 21 Aug 2005 11:33 GMT
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?
Lloyd Dupont - 21 Aug 2005 12:21 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.