Callbacks problems

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Callbacks problems

 
0
  #1
Apr 8th, 2009
Hey guys,

I've got a multithreaded application. The GUI runs on its own thread whilst a background worker thread will get invovked later on. Now the problem occurs when the bakground thread trys to manipulate the GUI thread.

Solution is a callback using invokeRequired.

  1. public void ThreadProcSafe2(String text)
  2. {
  3. if (this.m_AllKnownDevicesFrm.InvokeRequired)
  4. {
  5. // It's on a different thread, so use Invoke.
  6. SetTextCallback3 d = new SetTextCallback3(switchPanels);
  7. this.Invoke(d, new object[] {1} );
  8.  
  9. }
  10. else
  11. {
  12. switchPanels(1);
  13. }
  14. }

But this fails when its running... With error of

"invalid parameter"
switchPanels is a method declared to take an int has an agrument.

Confused. Can anyone shread any light onto this problem?

Thanks guys...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Callbacks problems

 
0
  #2
Apr 8th, 2009
try this

its unclear why you are using string text as a parameter if its not being passed on, but here it is

  1. void delegate textCallback(string text);
  2. public void ThreadProcSafe2(String text)
  3. {
  4. if (this.m_AllKnownDevicesFrm.InvokeRequired)
  5. {
  6. this.m_AllKnownDevicesFrm.Invoke(new textCallback(ThreadProcSafe2), text);
  7. }
  8. else
  9. {
  10. switchPanels(1);
  11. }
  12. }
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC