Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Windows;
  7.  
  8. namespace LVM
  9. {
  10.  
  11.     class MediaInfoThreaded
  12.     {
  13.         private static List<string> fileList;
  14.         private static ManualResetEvent[] resetEvents;
  15.         private static string[] wrkFolder;
  16.         private static MediaInfo[] wrkMediaInfo;
  17.         private static LvmDatabase db;
  18.  
  19.  
  20.         public static void ParseFolderThreaded(string[] paths, int numThreads)
  21.         {
  22.             resetEvents = new ManualResetEvent[numThreads];
  23.             wrkFolder = new string[numThreads];
  24.             wrkMediaInfo = new MediaInfo[numThreads];
  25.             db = new LvmDatabase();
  26.  
  27.            
  28.  
  29.         }
  30.  
  31.        
  32.            
  33.             for (int s = 0; s < numThreads; s++)
  34.             {
  35.                 resetEvents[s] = new ManualResetEvent(false);
  36.                 wrkMediaInfo[s] = new MediaInfo();
  37.                 ThreadPool.QueueUserWorkItem(DoWork, (object)s);
  38.             }
  39.            
  40.             //WaitHandle.WaitAll(resetEvents);
  41.         }
  42.  
  43.         private static void DoWork(object o)
  44.         {
  45.             int index = (int)o;
  46.             while (fileList.Count > 0)
  47.             {
  48.                 lock(fileList)
  49.                 {
  50.                     wrkFolder[index] = fileList.FirstOrDefault();
  51.                     fileList.Remove(wrkFolder[index]);
  52.                     Console.WriteLine(wrkFolder[index]);
  53.                 }
  54.                 wrkMediaInfo[index].OpenTest(wrkFolder[index]);
  55.                 wrkMediaInfo[index].Close();
  56.             }
  57.             resetEvents[index].Set();
  58.         }
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement