/// <summary>
        ///     Run the model if it is contained inside of a project.
        /// </summary>
        /// <param name="runName"></param>
        /// <param name="error">A message in case of error</param>
        /// <param name="executeNow">Should the run start executing now or wait for all other runs to finish first?</param>
        /// <param name="forceLocal">Execute in the local process, overriding default behaviour.</param>
        /// <returns>A reference to the run.</returns>
        public XTMFRun Run(string runName, ref string error, bool overwrite = false, bool executeNow = true,
                           bool forceLocal = false)
        {
            // this needs to block as if a command is running
            lock (_SessionLock)
            {
                if (!CanRun)
                {
                    error = "You can not run this model system.";
                    return(null);
                }

                lock (_RunningLock)
                {
                    XTMFRun run;
                    if (_ModelSystemIndex >= 0)
                    {
                        var cloneProject = ProjectEditingSession.CreateCloneProject(ProjectEditingSession.Project);
                        cloneProject.ModelSystemStructure[_ModelSystemIndex] =
                            ModelSystemModel.Root.RealModelSystemStructure;
                        cloneProject.ModelSystemDescriptions[_ModelSystemIndex] = ModelSystemModel.Description;
                        cloneProject.LinkedParameters[_ModelSystemIndex]        =
                            ModelSystemModel.LinkedParameters.GetRealLinkedParameters();


                        if (((Configuration)Configuration).RemoteHost)
                        {
                            run = XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                           _Runtime.Configuration, runName, overwrite);
                        }
                        else
                        {
                            run =
                                Debugger.IsAttached || forceLocal ||
                                !((Configuration)Configuration).RunInSeperateProcess
                                    ? XTMFRun.CreateLocalRun(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                             _Runtime.Configuration, runName, overwrite)
                                    : XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel,
                                                               _Runtime.Configuration, runName, overwrite);
                        }


                        run.ProjectSavedByRun += (theRun, newMSS) =>
                        {
                            string e = null;
                            ProjectEditingSession.Project.ModelSystemStructure[_ModelSystemIndex] = newMSS;
                            ProjectEditingSession.Project.Save(ref e);
                            Reload();
                            ProjectWasExternallySaved?.Invoke(this, new EventArgs());
                        };
                    }
                    else
                    {
                        run = XTMFRun.CreateLocalRun(ProjectEditingSession.Project, ModelSystemModel.Root,
                                                     _Runtime.Configuration, runName, overwrite);
                    }
                    return(run);
                }
            }
        }