Exemplo n.º 1
0
        public static Guid Register(AsyncCommandQueue queue)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            Guid guid = Guid.NewGuid();

            lock (sync) {
                queues.Add(guid, queue);
            }

            return(guid);
        }
Exemplo n.º 2
0
        protected virtual void OnTaskCompleted(TaskCompletedEventArgs e)
        {
            AsyncCommandQueue queue = commandQueue;
            EventHandler <TaskCompletedEventArgs> handler = Completed;

            if (queue != null)
            {
                queue.Register(new CommandWrapper(delegate {
                    if (handler != null)
                    {
                        handler(this, e);
                    }
                }));
            }
            else if (handler != null)
            {
                ThreadPool.QueueUserWorkItem(delegate {
                    handler(this, e);
                });
            }
        }
Exemplo n.º 3
0
        protected TaskGroup(int maxRunningTasks,
                            TaskCollection <T> tasks,
                            GroupStatusManager statusManager,
                            GroupProgressManager <T> progressManager)
        {
            if (maxRunningTasks < 0)
            {
                throw new ArgumentException("maxRunningTasks must be >= 0");
            }
            else if (tasks == null)
            {
                throw new ArgumentNullException("tasks");
            }

            sync         = tasks.SyncRoot;
            currentTasks = new List <T> (maxRunningTasks);

            commandQueue = new AsyncCommandQueue();
            id           = CommandQueueManager.Register(commandQueue);

            SetProgressManager(
                progressManager ?? new GroupProgressManager <T> ()
                );

            SetStatusManager(
                statusManager ?? new GroupStatusManager()
                );

            try {
                gsm.SuspendUpdate = true;

                gsm.RemainingTasks  = tasks.Count;
                gsm.MaxRunningTasks = maxRunningTasks;

                SetTaskCollection(tasks);
            } finally {
                gsm.SuspendUpdate = false;
                gsm.Update();
            }
        }
Exemplo n.º 4
0
        protected virtual void OnStatusChanged(TaskStatusChangedInfo tsci)
        {
            AsyncCommandQueue queue = commandQueue;
            EventHandler <TaskStatusChangedEventArgs> handler = StatusChanged;

            if (queue != null)
            {
                queue.Register(new CommandWrapper(delegate {
                    TaskStatusChangedEventArgs e = new TaskStatusChangedEventArgs(tsci);
                    if (handler != null)
                    {
                        handler(this, e);
                    }
                }));
            }
            else if (handler != null)
            {
                ThreadPool.QueueUserWorkItem(delegate {
                    handler(this, new TaskStatusChangedEventArgs(tsci));
                });
            }
        }
Exemplo n.º 5
0
        public FeedsManager(HyenaSqliteConnection connection, DownloadManager downloadManager, string podcast_base_dir)
        {
            // Hack to work around Feeds being needy and having to call all our internal methods, instead
            // of us just listening for their events.
            Instance = this;
            this.connection = connection;
            this.podcast_base_dir = podcast_base_dir;

            feed_manager = new FeedManager ();
            enclosure_manager = new EnclosureManager (downloadManager);

            Feed.Init ();
            FeedItem.Init ();
            FeedEnclosure.Init ();

            command_queue = new AsyncCommandQueue ();
        }
Exemplo n.º 6
0
        public void Dispose()
        {
            if (SetDisposed ()) {
                AutoResetEvent disposeHandle = new AutoResetEvent (false);

                feed_manager.Dispose (disposeHandle);
                enclosure_manager.Dispose (disposeHandle);

                if (command_queue != null) {
                    command_queue.Dispose ();
                    command_queue = null;
                }

                disposeHandle.Close ();
            }
        }