protected void ExecuteSubTasks(List <ThreadStart> tasks, int threadCount)
        {
            List <List <ThreadStart> > splittedTasks = new List <List <ThreadStart> >();

            for (int i = 0; i < threadCount; i++)
            {
                splittedTasks.Add(new List <ThreadStart>());
            }

            for (int i = 0; i < tasks.Count; i++)
            {
                splittedTasks[i % threadCount].Add(tasks[i]);
            }

            bool[]         completions = new bool[threadCount];
            SubTaskParam[] parameters  = new SubTaskParam[threadCount];

            for (int i = 0; i < threadCount; i++)
            {
                Thread t = new Thread(new ParameterizedThreadStart(SubTaskMain));
                parameters[i]          = new SubTaskParam();
                parameters[i].index    = i;
                parameters[i].tasks    = splittedTasks[i];
                parameters[i].complete = completions;

                t.Start(parameters[i]);
            }

            while (!AllFinished(completions))
            {
                Thread.Sleep(1000);

                OnLoadProgress?.Invoke(GetProgress(parameters));
            }
        }
Example #2
0
        protected virtual void UpdateLoadProgress()
        {
            var prevProgress = LoadProgress;
            var runnersCount = LoadRunners.Count + LocateRunners.Count;

            if (runnersCount == 0)
            {
                LoadProgress = 1f;
            }
            else
            {
                LoadProgress = Mathf.Min(1f / runnersCount, .999f);
            }
            if (prevProgress != LoadProgress)
            {
                OnLoadProgress?.Invoke(LoadProgress);
            }
        }