Exemple #1
0
        /// <summary>
        /// Download metar asynchronously.
        /// </summary>
        /// <param name="icao">Icao code of airport/station.</param>
        /// <param name="retriever">Metar retrievere used to decode metar from source stream</param>
        /// <param name="downloadCompletedDelegate">Delegate function raised when download is completed or error occured.</param>
        /// <exception cref="DownloadException">
        /// Raised when any error occurs.
        /// </exception>
        public static void DownloadAsync(string icao, IRetriever retriever,
                                         DownloadCompletedDelegate downloadCompletedDelegate)
        {
            Downloader d = new Downloader(retriever);

            d.DownloadAsync(icao, downloadCompletedDelegate);
        }
Exemple #2
0
        /// <summary>
        /// Download metar asynchronously.
        /// </summary>
        /// <param name="icao">Icao code of airport/station.</param>
        /// <param name="downloadCompletedDelegate">Delegate function raised when download is completed or error occured.</param>
        /// <exception cref="DownloadException">
        /// Raised when any error occurs.
        /// </exception>
        public void DownloadAsync(
            string icao, DownloadCompletedDelegate downloadCompletedDelegate)
        {
            System.Threading.Thread t = new System.Threading.Thread(
                new System.Threading.ThreadStart(DownloadAsynchronously));

            aIcao = icao;
            aDel  = downloadCompletedDelegate;

            t.Start();
        }
        public List <Thread> ThreadList; //当前运行的线程列表

        public DownloadTask(string savePath, TaskConfig taskconfig, Form_Download masterForm)
        {
            MasterForm = masterForm;
            downloadCompletedDelegate = MasterForm.DownloadCompleted;
            OutPutPrint         = MasterForm.PrintToListBox;
            CriticalSectionLock = new object();
            this.SavePath       = savePath;
            Config           = taskconfig;
            state            = DownloadState.Stop;
            CurrentThreads   = 0;
            DownloadProgress = 0.0;
            ThreadList       = new List <Thread>(10);
            if (Config.SupportResume)
            {
                SaveConfig();
            }
            if (!File.Exists(SavePath))
            {
                FileStream file = new FileStream(SavePath, FileMode.Create, FileAccess.Write);
                file.SetLength((long)Config.FileLength);
                file.Close();
            }
        }