Exemplo n.º 1
0
        /// <summary>
        /// Adds a request to the application threadpool
        /// </summary>
        /// <param name="request">A NetRequest object that we want performed</param>
        /// <returns>true if the request can be added</returns>
        public static bool AddRequest(NetRequest request)
        {
            lock (requestQueue)
            {
                if (activeRequests.Count > MAX_CONCURRENT_REQUESTS)
                {
                    if (request != null)
                    {
                        requestQueue.Enqueue(request);
                    }
                    return(false);
                }

                activeRequests.Add(request);
            }

#if iOS
            if (request.AbortRequested)
            {
                return(false);
            }
            request.Perform();
#else
            ThreadPool.QueueUserWorkItem(work =>
            {
                try
                {
                    if (request.AbortRequested)
                    {
                        return;
                    }
                    request.Perform();
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception ex)
                {
                    request.OnException(ex);
                }
            });
#endif

            return(true);
        }