예제 #1
0
        private bool Upload(string fileName)
        {
            bool result = false;

            foreach (Control ctl in flowLayoutPanel1.Controls)
            {
                if (ctl.Name == Path.GetFileNameWithoutExtension(fileName))
                {
                    _currentControl = ctl as UploadControl;
                    if (_currentControl.InvokeRequired)
                    {
                        Action actionDelegate = () =>
                        {
                            if (_currentControl.IsPause)
                            {
                                return;
                            }
                            result = true;
                            _currentControl.SetState(UploadState.Uploading);
                            backgroundWorker1.RunWorkerAsync(fileName);
                        };
                        // 或者
                        // Action<string> actionDelegate = delegate(string txt) { this.label2.Text = txt; };
                        _currentControl.Invoke(actionDelegate);
                    }
                    break;
                }
            }
            return(result);
        }
예제 #2
0
        private void AddQueue(string t)
        {
            _fileNames.Enqueue(t);
            UploadControl control = new UploadControl();

            control.FileName        = (flowLayoutPanel1.Controls.Count + 1) + "." + Path.GetFileNameWithoutExtension(t);
            control.Width           = flowLayoutPanel1.Width;
            control.Dock            = DockStyle.Top;
            control.Name            = Path.GetFileNameWithoutExtension(t);
            control.OnPauseChanged += control_OnPauseChanged;
            flowLayoutPanel1.Controls.Add(control);
        }
예제 #3
0
        private void control_OnPauseChanged(object sender, EventArgs e)
        {
            UploadControl control = sender as UploadControl;

            if (control == _currentControl)
            {
                bool isPause = control.IsPause;
                if (isPause)
                {
                    manualReset.Reset();
                    control.SetState(UploadState.Pause);
                }
                else
                {
                    manualReset.Set();
                    control.SetState(UploadState.Uploading);
                }
            }
        }