public void LongRunningTask()
    {
        while (WorkRemaining)
        {
            if (_queue.Any())
            {
                var workItem = _queue.Dequeue();
                if (workItem.Validate())
                {
                    workItem.Action(workItem.Data);
                }
                else
                {
                    NeedsAttention.Add(workItem);
                }
            }
            else
            {
                Thread.Sleep(500);         // check if the queue has items every 500ms
            }
        }
        var completedEvent = WorkCompleted;

        if (completedEvent != null)
        {
            completedEvent(this, EventArgs.Empty);
        }
    }
Ejemplo n.º 2
0
        public async Task Monitor(IEnumerable <ShareJobResult> results, KeyValueStorage kvs)
        {
            RedditSharpReader reader = new RedditSharpReader(new RedditSettings(kvs));

            foreach (ShareJobResult result in results)
            {
                Post post = await reader.GetPostInfo(result.Url);

                int upvoteThreshold  = kvs.GetInteger(RedditPostMonitorSettingsPage.UpvoteThreshold, 5);
                int commentThreshold = kvs.GetInteger(RedditPostMonitorSettingsPage.CommentTheshold, 5);
                if (post.Upvotes >= upvoteThreshold && post.CommentCount >= commentThreshold)
                {
                    NeedsAttention?.Invoke(this, new NeedsAttentionEventArgs(result,
                                                                             $"{result.Url} needs attention. {post.Upvotes} upvotes, {post.CommentCount} comments"));
                }
                System.Diagnostics.Debug.WriteLine($"upvoteThreshold = {upvoteThreshold}, commentThreshold = {commentThreshold}");
                System.Diagnostics.Debug.WriteLine($"post.Upvotes = {post.Upvotes}, post.CommentCount = {post.CommentCount}");
            }
        }