예제 #1
0
 public ThreadProcess Search(Queue <ISearchble>[] filesQueue, ActionWithThread <ISearchble> searchAndSaveIn)
 {
     return(process =>
     {
         var tasks = new System.Threading.Tasks.Task[filesQueue.Length];
         for (int i = 0; i < filesQueue.Length; i++)
         {
             var queue = filesQueue[i];
             tasks[i] = System.Threading.Tasks.Task.Run(() =>
             {
                 for (int j = 0; j < queue.Count; j++)
                 {
                     searchAndSaveIn(queue.Dequeue());
                 }
             });
         }
         System.Threading.Tasks.Task.Run(() =>
         {
             if (tasks.Wait())
             {
                 process();
             }
         });
     });
 }
예제 #2
0
        public ThreadProcess Search(Queue <ISearchble>[] filesQueue, ActionWithThread <ISearchble> searchAndSaveIn)
        {
            return((process) =>
            {
                var threads = new ThreadQueue <ISearchble> [filesQueue.Length];
                for (int i = 0; i < filesQueue.Length; i++)
                {
                    threads[i] = new ThreadQueue <ISearchble>(filesQueue[i], searchAndSaveIn);
                    threads[i].BeginProcessData();
                }

                var waitingThread = new Thread(() =>
                {
                    for (; ; Thread.Sleep(3000))
                    {
                        var count = 0;
                        for (var i = 0; i < threads.Length; i++)
                        {
                            if (threads[i].TheThread.ThreadState == ThreadState.Stopped)
                            {
                                count++;
                            }
                        }
                        if (count == threads.Length)
                        {
                            break;
                        }
                    }

                    var processThread = new Thread(new ThreadStart(process));
                    processThread.Start();
                });
                waitingThread.Start();
            });
        }
예제 #3
0
 public ThreadProcess Search(Queue <ISearchble>[] filesQueue, ActionWithThread <ISearchble> searchAndSaveIn)
 {
     return(async(process) =>
     {
         seachCTS = new CancellationTokenSource();
         var seachTC = seachCTS.Token;
         var totalCount = filesQueue.Count();
         var ProgressLayout = new Windows.ProgressWindow("Search")
         {
             CTS = seachCTS
         };
         var progress = new Progress <double>(ProgressLayout.ReportProgress);
         var realProgres = progress as IProgress <double>;
         ProgressLayout.Show();
         await System.Threading.Tasks.Task.Run(() =>
         {
             var tasks = new Task[filesQueue.Length];
             var tempCount = 0;
             for (int i = 0; i < filesQueue.Length; i++)
             {
                 var queue = filesQueue[i];
                 tasks[i] = Task.Run(() =>
                 {
                     try
                     {
                         for (int j = 0; j < queue.Count; j++)
                         {
                             seachTC.ThrowIfCancellationRequested();
                             searchAndSaveIn(queue.Dequeue());
                             //Interlocked.Increment(ref tempCount);
                             lock (_searchLock)
                                 realProgres.Report(++tempCount * 100 / (double)totalCount);
                         }
                     }
                     catch (OperationCanceledException)
                     {
                         GC.Collect(2);
                         GC.WaitForPendingFinalizers();
                     }
                 }, seachTC);
             }
             tasks.Wait();
         });
         ProgressLayout.Close();
         process();
     });
 }
예제 #4
0
 public ThreadProcess Search(Queue <ISearchble>[] filesQueue, ActionWithThread <ISearchble> searchAndSaveIn)
 {
     return((process) =>
     {
         Task.Factory.StartNew(() =>
         {
             ParallelLoopResult result = Parallel.ForEach(filesQueue, currentQueue =>
             {
                 for (int i = 0; i < currentQueue.Count; i++)
                 {
                     searchAndSaveIn(currentQueue.Dequeue());
                 }
             });
             if (result.IsCompleted)
             {
                 process();
             }
         });
     });
 }
예제 #5
0
 public ThreadQueue(Queue <T> queueOfFiles, ActionWithThread <T> func)
 {
     this._func         = func;
     this._queueOfFiles = queueOfFiles;
     TheThread          = new System.Threading.Thread(new ThreadStart(this.ThreadFunc));
 }