예제 #1
0
        public void ThreadProc()
        {
            // we're going to wait 2 minutes between calls to Download Images, so
            // set the interval to 120000 milliseconds

            int interval = 100000; // 2 minutes
            // this variable tracks how many milliseconds have gone by since
            // the last call to download image. Set it to zero to indicate we're
            // starting fresh
            int elapsed = 0;
            // because we don't want to use 100% of the CPU, we will be
            // sleeping for 1 second between checks to see if it's time to
            // call donwload image
            int waitTime = 1000; // 1 second

            try
            {
                // do this loop forever (or until the service is stopped)
                while (true)
                {
                    // if enough time has passed
                    if (interval >= elapsed)
                    {
                        // reset how much time has passed to zero
                        elapsed = 0;
                        // call DownloadImages()
                        PhotoCTMDownloader objDownloader = new PhotoCTMDownloader();
                        objDownloader.DownloadImages();
                    }
                    // Sleep for 1 second
                    Thread.Sleep(waitTime);
                    // indicate that 1 additional second has passed
                    elapsed += waitTime;
                }
            }
            catch (ThreadAbortException)
            {
                // we want to eat the excetion because we don't care if the
                // thread has aborted since we probably did it on purpose by
                // stopping the service.
            }
        }
예제 #2
0
        public void ThreadProc()
        {
            // we're going to wait 2 minutes between calls to Download Images, so
            // set the interval to 120000 milliseconds

            int interval = 100000; // 2 minutes
            // this variable tracks how many milliseconds have gone by since
            // the last call to download image. Set it to zero to indicate we're
            // starting fresh
            int elapsed = 0;
            // because we don't want to use 100% of the CPU, we will be
            // sleeping for 1 second between checks to see if it's time to
            // call donwload image
            int waitTime = 1000; // 1 second
            try
            {
                // do this loop forever (or until the service is stopped)
                while (true)
                {
                    // if enough time has passed
                    if (interval >= elapsed)
                    {
                        // reset how much time has passed to zero
                        elapsed = 0;
                        // call DownloadImages()
                        PhotoCTMDownloader objDownloader=new PhotoCTMDownloader();
                        objDownloader.DownloadImages();
                    }
                    // Sleep for 1 second
                    Thread.Sleep(waitTime);
                    // indicate that 1 additional second has passed
                    elapsed += waitTime;
                }
            }
            catch (ThreadAbortException)
            {
                // we want to eat the excetion because we don't care if the
                // thread has aborted since we probably did it on purpose by
                // stopping the service.
            }
        }