0

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.

public void ThreadProcSafe2(String text)
        {
            if (this.m_AllKnownDevicesFrm.InvokeRequired)
            {
                // It's on a different thread, so use Invoke.
                SetTextCallback3 d = new SetTextCallback3(switchPanels);
                this.Invoke(d, new object[] {1} );
                
            }
            else
            {
                switchPanels(1);
            }
        }

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...

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by dickersonka
0

try this

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

void delegate textCallback(string text);
public void ThreadProcSafe2(String text)
        {
            if (this.m_AllKnownDevicesFrm.InvokeRequired)
            {
                this.m_AllKnownDevicesFrm.Invoke(new textCallback(ThreadProcSafe2), text);                
            }
            else
            {
                switchPanels(1);
            }
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.