Hey guys,

I've got this code implemented below in my UI form... and calling it from another thread. On debugging the 'else' part throws an TargetParameterCountException...

I'm clueless has to why...

public delegate void SolveDrawMaze(Cell aCell);

        public void SolveDraw(Cell aCell)
        {
            if (InvokeRequired)
            {
                this.BeginInvoke(new SolveDrawMaze(DoMe));
            }
            else
            {
                DoMe(aCell);
            }
        }


        public void DoMe(Cell aCell)
        {
            
        }

Recommended Answers

All 2 Replies

The UI thread cannot be directly accessed by other threads. You have invoke a delegate to perform the changes on the UI.
Theres an example here.

I think you should be using Invoke not BeginInvoke.
BeginInvoke is asynchronous and requires an EndInvoke some time later.
You also need to pass the parameters for the Invoked method.

if (InvokeRequired)
            {
                this.Invoke(new SolveDrawMaze(DoMe), new object[] { aCell});
            }
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.