예제 #1
0
        private void SearchInThread(ThreadProcess StartThread)
        {
            var fileDialog = new SaveFileDialog
            {
                Filter       = "All Files | *.* ",
                AddExtension = true,
                DefaultExt   = "txt"
            };

            //getting full file name, where we'll save the txt
            if (fileDialog.ShowDialog() == true)
            {
                _passport  = new List <Group>();
                _number    = new List <Group>();
                _tin       = new List <Group>();
                _pin       = new List <Group>();
                _email     = new List <Group>();
                _ftp       = new List <Group>();
                _vk        = new List <Group>();
                _exeptions = new StringBuilder();
                var messageBoxResult = System.Windows.MessageBox.Show("Would you like to open the file after the search is complete?",
                                                                      "Are you sure?", System.Windows.MessageBoxButton.YesNo);
                var fileName = fileDialog.FileName;
                StartThread(() =>
                {
                    using (var writer = new StreamWriter(fileName))
                    {
                        writer.Write(WriteInStream().ToString());
                    }
                    MessageBox.Show(_exeptions.ToString(),
                                    "Attention!", MessageBoxButton.OK);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        try
                        {
                            Process.Start(fileName);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                });
            }
        }
예제 #2
0
        private void SetUpWorkerThreads()
        {
            _threadCount = tbProccessors.Value;

            bccFile?.CompleteAdding();

            foreach (ThreadProcess tp in _threads)
            {
                StatusPanel.Controls.Remove(tp.threadLabel);
                tp.threadLabel.Dispose();

                StatusPanel.Controls.Remove(tp.threadProgress);
                tp.threadProgress.Dispose();

                tp.cProcessZip.ProcessFileStartCallBack = null;
                tp.cProcessZip.StatusCallBack           = null;
                tp.cProcessZip.ProcessFileEndCallBack   = null;
                tp.thread.Join();
            }

            bccFile?.Dispose();

            _threads.Clear();
            bccFile = new BlockingCollection <cFile>();

            for (int i = 0; i < _threadCount; i++)
            {
                ThreadProcess threadProcess = new ThreadProcess();
                _threads.Add(threadProcess);

                Label pLabel = new Label
                {
                    Visible = true,
                    Left    = 12,
                    Top     = 235 + 30 * i,
                    Width   = 225,
                    Height  = 15,
                    Text    = $"Processor {i + 1}"
                };

                StatusPanel.Controls.Add(pLabel);
                threadProcess.threadLabel = pLabel;

                ProgressBar pProgress = new ProgressBar
                {
                    Visible = true,
                    Left    = 12,
                    Top     = 250 + 30 * i,
                    Width   = 225,
                    Height  = 12
                };
                StatusPanel.Controls.Add(pProgress);
                threadProcess.threadProgress = pProgress;


                CProcessZip cpzn = new CProcessZip
                {
                    ThreadId = i,
                    bcCfile  = bccFile,
                    ProcessFileStartCallBack = ProcessFileStartCallback,
                    StatusCallBack           = StatusCallBack,
                    ProcessFileEndCallBack   = ProcessFileEndCallback,
                    pauseCancel = pc
                };
                Thread t = new Thread(cpzn.MigrateZip);
                t.Start();
                threadProcess.thread      = t;
                threadProcess.cProcessZip = cpzn;
            }

            if (Height < 325 + 30 * _threadCount)
            {
                Height = 325 + 30 * _threadCount;
            }
        }
예제 #3
0
		internal static void Init (int _nThreadCount)
		{
			lock (m_Lock) {
				m_nRefCount++;
				if (m_nRefCount == 1) {
					m_Processes = new MPCList<dLightWeightProcessBase> ();

					ThreadProcess.Init ();

					m_Threads = new List<Thread> ();
					int nThreadCount = _nThreadCount;
					for (int i = 0; i < nThreadCount; i++) {
						Thread thread = new Thread (delegate () { ThreadProcess process = new ThreadProcess (); process.MainLoop (); });
						thread.Name = String.Format ("dLightWeightProcessThread_{0}", i);
						thread.Start ();

						m_Threads.Add (thread);
					}
				}
			}
		}