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

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);
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.