Esempio n. 1
0
        public void ResetUpdate(string name, string path)
        {
            if (irDir.TryGetValue(name, out IAsyncResult ir))
            {
                if (ir.IsCompleted)
                {
                    Action <UserControl1, int, int> updateProgress = progressBarShow;
                    MethodCaller mc = new MethodCaller(FTPHelper.FtpUploadBroken);
                    //启动上传的异步委托
                    IAsyncResult rets = mc.BeginInvoke(path, pathStr1, updateProgress, null, null);
                    Stopwatch    time = new Stopwatch();
                    time.Start();
                    tempChange tc = new tempChange(UpdateResult);
                    tc.BeginInvoke(mc, rets, path, time, -1, null, null);
                }
            }

            foreach (UserControl1 item in panel1.Controls)
            {
                if (item.label1.Text == name)
                {
                    item.label2.Text = "上传中";
                    break;
                }
            }
            keyValues[name] = 2;
        }
Esempio n. 2
0
        /// <summary>
        /// 上传线程
        /// </summary>
        public void UpdateStart()
        {
            var path = strpath;
            //滚动条
            Action <UserControl1, int, int> updateProgress = progressBarShow;
            List <Stopwatch> time = new List <Stopwatch>();   //计时器

            CheckForIllegalCrossThreadCalls = false;
            List <string> splitFilePath = null;

            for (int i = 0; i < path.Length; i++)
            {
                if (ConfirmSplit.Checked)
                {
                    splitFilePath = SplitFile(path[i]);  //切割文件
                }
                if (splitFilePath == null)
                {
                    splitFilePath = new List <string>();
                    splitFilePath.Add(path[i]);
                }
                //生成自定义控件
                CreateControl(splitFilePath);
                List <MethodCaller> mcs    = new List <MethodCaller>();
                List <IAsyncResult> ret    = new List <IAsyncResult>();
                List <MethodCaller> mcsTmp = new List <MethodCaller>();
                flags = new int[splitFilePath.Count];
                for (int j = 0; j < splitFilePath.Count; j++)
                {
                    time.Add(new Stopwatch());
                    time[j].Start();
                    //上传封装到委托
                    MethodCaller mc = new MethodCaller(FTPHelper.FtpUploadBroken);
                    mcs.Add(mc);
                    mcsTmp.Add(mc);
                    //启动上传的异步委托
                    IAsyncResult rets = mcs[j].BeginInvoke(splitFilePath[j], pathStr1, updateProgress, null, null);
                    ret.Add(rets);
                    var      fileInfo = new FileInfo(splitFilePath[j]);
                    string[] temp     = fileInfo.Name.Split(new string[] { fileInfo.Extension }, StringSplitOptions.None);
                    ChangeControl(splitFilePath[j], "上传中", "0");
                    keyValues.Add(temp[0], 0);
                    irDir.Add(temp[0], rets);
                    //上传结果封装到委托
                    tempChange tc = new tempChange(UpdateResult);
                    //启动上传结果处理的异步委托
                    tc.BeginInvoke(mcs[j], ret[j], splitFilePath[j], time[j], j, null, null);

                    int taskNumber = Convert.ToInt32(taskComboBox.Text);
                    //同时进行最大任务数
                    while (mcsTmp.Count >= taskNumber)
                    {
                        bool isBreak = false;
                        //等待任务结果
                        while (!isBreak)
                        {
                            for (int x = 0; x < flags.Length; x++)
                            {
                                if (flags[x] == 1)
                                {
                                    flags[x] = 2;
                                    isBreak  = true;
                                    break;
                                }
                            }
                            Thread.Sleep(500);
                        }
                        mcsTmp.Remove(mcs[j]);
                    }
                }
            }
            bool isOver = false;

            //等待全部完成
            while (!isOver)
            {
                for (int x = 0; x < flags.Length; x++)
                {
                    if (flags[x] == 0)
                    {
                        isOver = false;
                        break;
                    }
                    isOver = true;
                }
                Thread.Sleep(500);
            }
            MessageBox.Show("上传结束!");
        }