Exemple #1
0
 /// <summary>
 /// Enque the url for downloading
 /// </summary>
 /// <param name="url">url to download</param>
 /// <param name="highPriority">priority to use</param>
 public static void prefetch(string url, bool highPriority)
 {
     if (fetchProcesses.ContainsKey(url))
     {
         //update the process, as a priority change
         ((DownloadThread)fetchProcesses[url]).highPriority = highPriority;
     }
     else
     {
         //create a new process
         DownloadThread f = new DownloadThread(url, highPriority);
         fetchProcesses.Add(url, f);
     }
 }
Exemple #2
0
        protected static void retreivalThread()
        {
            string url = null;

            while (true)
            {
                //long wait for 1/10th of a second
                Thread.Sleep(100);

                lock (fetchProcesses)
                {
                    url = getNextProcessToService();
                }

                //is there a url to service
                if (url != null)
                {
                    DownloadThread f = (DownloadThread)fetchProcesses[url];

                    //lock the fetchProcess and start retrieving
                    if (f.locked.WaitOne(1000, false))
                    {
                        f.flagStarted();
                        try
                        {
                            //TODO: must set up a single monitior thread to terminate any instances of this
                            //		thread that lock indefinatly in this function call
                            object data = retriveURL(f.url);
                            if (data == null)
                            {
                                f.flagFailed();
                            }
                            else
                            {
                                //TODO: Parse in the actual file time stamp
                                f.setData(data, DateTime.Now);
                            }
                        }
                        finally
                        {
                            f.locked.ReleaseMutex();
                        }
                    }
                }
            }
        }