Beispiel #1
0
        public async Task RunAllAlgorithms()
        {
            List <Task <int> > tasks = new List <Task <int> >();

            for (int i = 0; i < Context.Algorithms.Count(); i++)
            {
                if (!_running.Contains(i))
                {
                    _running.Add(i);
                    AlgorithmStarted?.Invoke(this, new AlgorithmEventArgs(i));

                    Task <int> task = Task.Run(() => RunAlgorithm(i));
                    tasks.Add(task);
                    _tasks.Add(task);
                }
            }

            while (tasks.Any())
            {
                Task <int> finished = await Task.WhenAny(tasks);

                _running.Remove(finished.Result);
                tasks.Remove(finished);
                _tasks.Remove(finished);
            }
        }
Beispiel #2
0
        public async Task RunSingleAlgorithm(int Index)
        {
            if (Context.Algorithms.Count() <= Index || Index < 0)
            {
                return;
            }

            if (!_running.Contains(Index))
            {
                _running.Add(Index);
                AlgorithmStarted?.Invoke(this, new AlgorithmEventArgs(Index));

                Task <int> task = Task.Run(() => RunAlgorithm(Index));

                _running.Remove(await task);
                _tasks.Remove(task);
            }
        }
 protected virtual void OnAlgorithmStarted(EventArgs e) => AlgorithmStarted?.Invoke(this, e);