示例#1
0
        public void Work()
        {
            try
            {
                filenames = new ConcurrentQueue <string>(Directory.GetFiles(_img_path, "*.jpg"));
            }
            catch (DirectoryNotFoundException exc)
            {
                ErrMessage?.Invoke("Directory doesn't exist!");
                return;
            }

            _stopSignal = new ManualResetEvent(false);
            var max_proc_count = Environment.ProcessorCount;

            Thread[] threads = new Thread[max_proc_count];
            for (int i = 0; i < max_proc_count; ++i)
            {
                InfoMessage?.Invoke("Statring thread");
                threads[i] = new Thread(worker);
                threads[i].Start();
            }

            InfoMessage?.Invoke("Done!");
        }
示例#2
0
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                if (_stopSignal.WaitOne(0))
                {
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                ResultEvent?.Invoke(Predict(ImageToTensor(name), name));
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }
示例#3
0
        //public void Stop() => _ct.Cancel();
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                //Console.WriteLine("here working");
                if (_ct.IsCancellationRequested || _stopSignal.WaitOne(0))
                {
                    Console.WriteLine("sssss");
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                //Console.WriteLine("here after");
                var current_res = Predict_with_db(ImageToTensor(name), name);
                ResultEvent?.Invoke(current_res);
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }