Exemplo n.º 1
0
        private void HttpConRequestComplete(object sender, EventArgs e)
        {
            var httpCon = (HttpConnection)sender;

            DeleteOldTasksFromQueue();

            HttpTask task = null;

            lock (SyncRoot)
            {
                if (TasksQueue.Count > 0)
                {
                    task = TasksQueue[0];
                    TasksQueue.RemoveAt(0);
                }
                else
                {
                    _freeList.Add(httpCon);
                }
            }

            if (task != null)
            {
                task.Execute(httpCon);
            }
        }
Exemplo n.º 2
0
        public Task <bool> ExecuteTaskAsync(HttpTask task)
        {
            DeleteOldTasksFromQueue();

            HttpConnection conn = null;

            using (new PerfLimit("Start task"))
                lock (SyncRoot)
                {
                    if (_freeList.Count > 0)
                    {
                        conn = _freeList[0];
                        _freeList.RemoveAt(0);
                    }

                    if (conn == null && Connections.Count < ConnectionsLimit)
                    {
                        conn = new HttpConnection();
                        conn.ReceiveTimeout           = ReceiveTimeout;
                        conn.ConnectionStatusChanged += HttpConConnectionStatusChanged;
                        conn.RequestComplete         += HttpConRequestComplete;
                        Connections.Add(conn);
                    }

                    if (conn == null)
                    {
                        if (TasksQueue.Count < QueueLimit)
                        {
                            TasksQueue.Add(task);
                        }
                        else
                        {
                            Logger.Error("Dropping task because of full queue");
                            task.Cancel();
                        }
                    }
                }

            if (conn != null)
            {
                task.Execute(conn);
            }

            return(task.GetTask());
        }