コード例 #1
0
        public JobProxy <T> StartOrQueue(Func <JobManager <T>, T> ctr, bool attach = true)
        {
            var newjob = ctr(this);

            lock (LockObject)
            {
                foreach (var cjob in _activeJobs)
                {
                    if (cjob.Source == newjob.Source)
                    {
                        cjob.IncrementProxyRequests();
                        if (!attach)
                        {
                            return(null);
                        }
                        Console.Out.WriteLine($"Attach new proxy to Job [{cjob.Name}] ({cjob.ProxyCount + 1} attached proxies)");
                        return(JobProxy <T> .Create(cjob));
                    }
                }
                foreach (var cjob in _queuedJobs)
                {
                    if (cjob.Source == newjob.Source)
                    {
                        cjob.IncrementProxyRequests();
                        if (!attach)
                        {
                            return(null);
                        }
                        Console.Out.WriteLine($"Attach new proxy to Job [{cjob.Name}] ({cjob.ProxyCount + 1} attached proxies)");
                        return(JobProxy <T> .Create(cjob));
                    }
                }

                if (_activeJobs.Count < MaxParallelism)
                {
                    Console.Out.WriteLine($"Start new Job [{newjob.Name}] (direct)");
                    _activeJobs.Add(newjob);
                    newjob.Start();
                    return(attach ? JobProxy <T> .Create(newjob) : null);
                }
                else
                {
                    Console.Out.WriteLine($"Enqueue new Job [{newjob.Name}] ({_queuedJobs.Count} jobs in queue) ({RunningCountStr} jobs running)");
                    _queuedJobs.Add(newjob);
                    return(attach ? JobProxy <T> .Create(newjob) : null);
                }
            }
        }
コード例 #2
0
        public JobProxy <T> GetProxyOrNullLockless(Func <JobManager <T>, T> ctr)
        {
            var newjob = ctr(this);

            foreach (var cjob in _activeJobs)
            {
                if (cjob.Source == newjob.Source)
                {
                    Console.Out.WriteLine($"Attach new proxy to Job [{cjob.Name}] ({cjob.ProxyCount + 1} attached proxies)");
                    return(JobProxy <T> .Create(cjob));
                }
            }
            foreach (var cjob in _queuedJobs)
            {
                if (cjob.Source == newjob.Source)
                {
                    Console.Out.WriteLine($"Attach new proxy to Job [{cjob.Name}] ({cjob.ProxyCount + 1} attached proxies)");
                    return(JobProxy <T> .Create(cjob));
                }
            }

            return(null);
        }