Exemple #1
0
        private void BAdd_Click(object sender, RoutedEventArgs e)
        {
            if (_handles.Count == MaxThreadCount)
            {
                return;
            }

            var added  = false;
            var thread = _pool.QueueUserTask(TaskFunction);

            try
            {
                _handles.Add(thread);
                added = true;
            }
            catch (Exception exception)
            {
                LbLog.Items.Add(exception.Message);
                _handles.Remove(thread);
            }

            if (added)
            {
                LThreads.Content = $"Thread count: {_handles.Count}";
            }
        }
Exemple #2
0
        private void CopyClick(object sender, MouseButtonEventArgs e)
        {
            if (_pool == null)
            {
                MessageBox.Show("You should enter and save value of thread count first.");
                return;
            }

            if (LSource.Content == null)
            {
                MessageBox.Show("You should choose source file first.");
                return;
            }

            if (LDestination.Content == null)
            {
                MessageBox.Show("You should choose destination file first.");
                return;
            }

            _complete = 0;
            var source      = LSource.Content;
            var destination = LDestination.Content;
            var sourceFile  = new FileInfo(source.ToString());

            _destFile = new FileInfo(destination.ToString());
            if (_destFile.Exists)
            {
                _destFile.Delete();
            }
            var file = _destFile.Create();

            file.Dispose();
            PbProgress.Maximum = sourceFile.Length;
            var i = 0L;

            while (i < sourceFile.Length)
            {
                var i1 = i;

                _currentTask.Add(_pool.QueueUserTask(() => Task(sourceFile, _destFile, i1), Callback));
                i += Step;
            }
        }