943,708 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 814
  • C# RSS
Apr 8th, 2009
0

Callbacks problems

Expand Post »
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.

C# Syntax (Toggle Plain Text)
  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

Quote ...
"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...
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Apr 8th, 2009
0

Re: Callbacks problems

try this

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

C# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Cannot open 2 or more outlook contact detail
Next Thread in C# Forum Timeline: Totaling and averaging column in datagridview





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC