public static void DeleteTask()
 {
     _taskCount -= 1;
     Debug.WriteLine(Thread.CurrentThread + "|Task deleted" + Multithreading.GetTaskCount() + " | " + Multithreading.GetMaxTaskCount());
     if (_taskCount < 0)
     {
         _taskCount = 0;
     }
 }
Exemplo n.º 2
0
        private void DownImgAsync(string imgUrl)
        {
            var taskCount    = Multithreading.GetTaskCount();
            var maxTaskCount = Multithreading.GetMaxTaskCount();

            if (taskCount > maxTaskCount)
            {
                while (taskCount > maxTaskCount)
                {
                    taskCount    = Multithreading.GetTaskCount();
                    maxTaskCount = Multithreading.GetMaxTaskCount();
                    Thread.Sleep(10);
                }
            }
            Multithreading.AddTask();
            Image img = DownloadImage(imgUrl);

            OnDownloadComplete(img);
            Multithreading.DeleteTask();
        }