I performed a genetic algorithm that loops 10 times where each time I call the "FitnessFunction" function, I use a background worker to move an object on the topology and once it reach a specific point then I cancel that background worker and back to the "Genetic_Algorithm" function...
Unfortunately, I got the following error:
Cross-thread operation not valid: Control 'topology' accessed from a thread other than the thread it was created on...
What I have tried:
Run the background worker each time I call "FitnessFunction" function" which is responsible to stop it under a specific condition.
WinForms forbids to access Controls from other threads than the main UI.
Use
Invoke(..)
method of the form or useSynchronizationContext
class.