コード例 #1
0
        public static void DownloadWaiterFunc(object o)
        {
            var mission = (DownloadMission)o;

            while (!WaitHandle.WaitAll(mission.DoneEvents, 16))
            {
                float DownloadSpeed = 0;
                float DownloadSize  = 0;
                foreach (var i in mission.Params)
                {
                    DownloadSize += i.mDownloadSize;
                    WaitHandle[] tmp = { i.mDoneEvent };
                    if (!WaitHandle.WaitAll(tmp, 1))
                    {
                        DownloadSpeed += i.mSpeed;
                    }
                    else
                    {
                        i.mSpeed = 0;
                    }
                }

                string DownloadSpeedStr = UnitTrans.GetHandSomeNumFromByteNum((long)DownloadSpeed);
                float  percent          = DownloadSize / mission.FileSize * 100.0f;
                mission.DownloadPercent = percent;
                // (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView.Rows[mission.DataIndex].Cells[6].ValueType = Type.GetType("float");
                (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView.Rows[mission.DataIndex].Cells[6].Value = (int)(mission.DownloadPercent * 100);
                (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView.Rows[mission.DataIndex].Cells[4].Value = DownloadSpeedStr + @"/s";
                Console.WriteLine(percent);
            }
            (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView.Rows[mission.DataIndex].Cells[2].Value = "Migrating";
            MergeFile(mission.Params);
            (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView.Rows[mission.DataIndex].Cells[2].Value = "Complate";
        }
コード例 #2
0
        public void AddMission(string url, int ThreadCount)
        {
            //UInt32.MaxValue
            long fileSize            = HttpHelper.GetHttpLength(url, 6000);
            var  MissionDataGridView = (FormManager.GetFormManager().FormMap["MainForm"] as Form1).MissionDataGridView;
            var  allCells            = MissionDataGridView.Rows[MissionDataGridView.RowCount - 2].Cells;

            allCells[1].Value = UnitTrans.GetHandSomeNumFromByteNum(fileSize);

            var tmpFileDownloader = new FileDownloader(url, fileSize);

            DownloadFiles.Add(tmpFileDownloader);
            var tmpMission = new DownloadMission();

            tmpMission.DataIndex   = MissionDataGridView.RowCount - 2;
            tmpMission.FileSize    = fileSize;
            tmpMission.StartEvents = new ManualResetEvent[ThreadCount];
            tmpMission.DoneEvents  = new ManualResetEvent[ThreadCount];
            tmpMission.Params      = new ThreadParam[ThreadCount];
            tmpMission.Threads     = new Thread[ThreadCount];
            for (Int32 i = 0; i < ThreadCount; i++)
            {
                tmpMission.StartEvents[i]        = new ManualResetEvent(false);
                tmpMission.DoneEvents[i]         = new ManualResetEvent(false);
                tmpMission.Params[i]             = new ThreadParam();
                tmpMission.Params[i].mId         = i;
                tmpMission.Params[i].url         = url;
                tmpMission.Params[i].mStartEvent = tmpMission.StartEvents[i];
                tmpMission.Params[i].mDoneEvent  = tmpMission.DoneEvents[i];
                tmpMission.Threads[i]            = new Thread(new ParameterizedThreadStart(AsyncDownloadFile));
                tmpMission.Threads[i].Start(tmpMission.Params[i]);
            }
            CutFile(tmpMission.Params, fileSize);

            for (Int32 j = 0; j < ThreadCount; j++)
            {
                tmpMission.Params[j].mFileName = Guid.NewGuid().ToString().ToLower();
                tmpMission.Params[j].mDoneEvent.Reset();
                tmpMission.Params[j].mStartEvent.Set();
            }
            Thread tmpWaiter = new Thread(new ParameterizedThreadStart(DownloadWaiterFunc));

            tmpWaiter.Start(tmpMission);

            DownloadMissions.Add(tmpMission);
            DownloadMissionWaiter.Add(tmpWaiter);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: xuanzangfashi/MyDownloader
        static void DetialsUpdateThreadFunc(object o)
        {
            while (true)
            {
                var Obj = (MissionDetailsDataObj)o;
                if (!Obj._MissionDetials.Visible)
                {
                    continue;
                }

                int i = 0;
                foreach (var j in Obj.Params)
                {
                    Obj._MissionDetials.MissionDetialsDataView.Rows[i].Cells[1].Value = UnitTrans.GetHandSomeNumFromByteNum((long)j.mSpeed) + @"/s";
                    Obj._MissionDetials.MissionDetialsDataView.Rows[i].Cells[5].Value = UnitTrans.GetHandSomeNumFromByteNum((long)j.mDownloadSize);
                    i++;
                }
                //Obj._MissionDetials.Refresh();
            }
        }