Example #1
0
        void Upload(string fileName, string filePath)
        {
            _loadingUserControl.Show(this);

            _loadingUserControl.Message = "正在准备上传文件...";

            Log($"正在准备上传文件{fileName}...");

            Task.Run(() =>
            {
                try
                {
                    long size = 0;

                    _client.Upload(filePath, (o, c) =>
                    {
                        if (c == 0)
                        {
                            return;
                        }
                        size = c;
                        _loadingUserControl.Message = $"正在上传文件:{fileName},{(o * 100 / c)}%";
                    });

                    var fun = new Func <bool>(() =>
                    {
                        if (_client.FileSize(fileName) == size)
                        {
                            Log($"上传文件{fileName}成功");

                            textBox2_TextChanged(null, null);

                            return(true);
                        }
                        ThreadHelper.Sleep(1000);
                        return(false);
                    });

                    while (true)
                    {
                        if (fun.Invoke())
                        {
                            break;
                        }
                        if (size == 1)
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log("上传文件失败,fileName:" + fileName, ex.Message);
                }
                finally
                {
                    _loadingUserControl.Hide(this);
                }
            });
        }
Example #2
0
        private void FtpClientForm_Load(object sender, EventArgs e)
        {
            _loadingUserControl = new LoadingUserControl();

            _loadingUserControl.Size = this.Size;

            _loadingUserControl.Hide(this);

            this.Controls.Add(_loadingUserControl);

            this.Controls.SetChildIndex(_loadingUserControl, 9999);
        }
Example #3
0
        void Upload(string fileName, string filePath)
        {
            _loadingUserControl.Show(this);

            _loadingUserControl.Message = "正在准备上传文件...";

            Task.Run(() =>
            {
                try
                {
                    long size = 0;

                    _client.Upload(filePath, (o, c) =>
                    {
                        size = c;
                        _loadingUserControl.Message = $"正在上传文件:{fileName},{(o * 100 / c)}%";
                    });

                    var rs = _client.FileSize(fileName);

                    if (rs == size)
                    {
                        Log("上传文件成功,fileName:" + fileName);

                        textBox2_TextChanged(null, null);
                    }
                    else
                    {
                        Log("上传文件失败,fileName:" + fileName, "未能完整上传文件!");
                    }
                }
                catch (Exception ex)
                {
                    Log("上传文件失败,fileName:" + fileName, ex.Message);
                }
                finally
                {
                    _loadingUserControl.Hide(this);
                }
            });
        }