Exemplo n.º 1
0
        private void StartPeriodicDownloadAgent()
        {
            // Obtain a reference to the period task, if one exists
            this.periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (this.periodicTask != null)
            {
                BackgroundDownloader.RemoveAgent(periodicTaskName);
            }

            this.periodicTask = new PeriodicTask(periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            this.periodicTask.Description = periodicTaskDescription;

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(this.periodicTask);
                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if (DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(15));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Exemplo n.º 2
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     BackgroundDownloader downloader = new BackgroundDownloader();
     downloader.CreateDownload("{id: \"123456789\", downloadUri: \"https://dl.dropboxusercontent.com/u/77441826/1.txt\", resultFilePath: \"newFile.txt\", minInterval: 120}");
 }