private void downloadProfileFiles(ref ISet <string> idSet)
 {
     foreach (var id in idSet)
     {
         GraphApiContentSaver.enqueueDownloadProfileFile(id);
     }
 }
 private static void processQueue()
 {
     while (true)
     {
         if (downloadQueue.Count > 0)
         {
             string id = (string)downloadQueue.Dequeue();
             try
             {
                 var    saver      = new GraphApiContentSaver(id);
                 Thread downThread = new Thread(new ThreadStart(saver.save));
                 downThread.IsBackground = true;
                 downThread.Start();
             }
             catch (Exception)
             { }
         }
         Thread.Sleep(downloadInterval);
     }
 }
        public void beginProcessing()
        {
            IsRunning = true;
            while (userIdsToProcess.Count != 0 && !aborted)
            {
                if (currentDepth == maxDepth)
                {
                    breakEnqueueNew();
                }

                Stopwatch swatch = new Stopwatch();
                swatch.Start();
                var idToProcess = userIdsToProcess.Dequeue();
                progressListener.setTaskInfo(idToProcess, messages.FriendList);
                progressListener.reportQueueChange(usersWereInQueue.Count - userIdsToProcess.Count, usersWereInQueue.Count, ref userIdsToProcess);
                SourceContentSaver friendsSaver = new FriendsSourceContentSaver(idToProcess);
                var friendList = friendsSaver.saveFileAndGetIds();
                friendsSaver = null;
                friendList.ExceptWith(usersWereInQueue);


                if (enqueueNew)
                {
                    usersWereInQueue.UnionWith(friendList);
                    foreach (var userId in friendList)
                    {
                        userIdsToProcess.Enqueue(userId);
                    }
                }

                friendList = null;

                //downloadProfileFiles(friendList);
                GraphApiContentSaver.enqueueDownloadProfileFile(idToProcess);

                progressListener.setTaskInfo(idToProcess, messages.Favorites);
                SourceContentSaver likesSaver = new LikesSourceContentSaver(idToProcess);
                var likesList = likesSaver.saveFileAndGetIds();
                likesSaver = null;

                likesList.ExceptWith(downloadedPages);
                downloadedPages.UnionWith(likesList);

                downloadProfileFiles(ref likesList);

                likesList = null;

                swatch.Stop();
                taskTime.Add(swatch.ElapsedMilliseconds);
                string estimatedTime = computeEstimatedTime();
                progressListener.reportTaskDone(idToProcess, estimatedTime);
                int downloadedCount = usersWereInQueue.Count - userIdsToProcess.Count;
                if (downloadedCount >= nextDepthLevel)
                {
                    nextDepthLevel = usersWereInQueue.Count;
                    currentDepth++;
                }
                saveWorkStatus();

                if (singleProcessProfiles < maxSingleProcessProfiles)
                {
                    singleProcessProfiles++;
                }
                else
                {
                    restartApplication();
                }

                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
            }
            IsRunning = false;
            if (aborted)
            {
                Application.Exit();
            }
            else
            {
                waitForProfiles();
                progressListener.reportFinnish();
            }
        }