Windows Phone period task, function not executing

Posted by Special K. on Stack Overflow See other posts from Stack Overflow or by Special K.
Published on 2012-10-20T22:03:56Z Indexed on 2012/10/20 23:01 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

I'm trying to execute a code (to parse an XML to be more precisely, and after that I'll toast message the user with some new info's), but the class function AccDetailsDownloaded is not executed (is simply skipped), also the memory usage is ~2mb out of 6, here is my code:

if (task is PeriodicTask)
            {
                getData();
            }
            else
            {
                getData();
            }




            // If debugging is enabled, launch the agent again in one minute.
#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif

            // Call NotifyComplete to let the system know the agent is done working.
            NotifyComplete();
        }

        public void getData()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            string url = "http://example.com/example.xml";

            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                MessageBox.Show("No network connection available!");
                return;
            }
            // start loading XML-data
            WebClient downloader = new WebClient();
            Uri uri = new Uri(url, UriKind.Absolute);
            downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AccDetailsDownloaded);
            downloader.DownloadStringAsync(uri);

            string toastTitle = "";
            toastTitle = "Periodic ";

            string toastMessage = "Mem usage: " + DeviceStatus.ApplicationPeakMemoryUsage +
                "/" + DeviceStatus.ApplicationMemoryUsageLimit;

            // Launch a toast to show that the agent is running.
            // The toast will not be shown if the foreground application is running.
            ShellToast toast = new ShellToast();
            toast.Title = toastTitle;
            toast.Content = toastMessage;
            toast.Show();
        }

        void AccDetailsDownloaded(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Result == null || e.Error != null)
            {
                MessageBox.Show("There was an error downloading the XML-file!");
            }
            else
            {
                string toastTitle = "";
                toastTitle = "Periodic ";

                string toastMessage = "Mem usage: " + DeviceStatus.ApplicationPeakMemoryUsage +
                    "/" + DeviceStatus.ApplicationMemoryUsageLimit;

                // Launch a toast to show that the agent is running.
                // The toast will not be shown if the foreground application is running.
                ShellToast toast = new ShellToast();
                toast.Title = toastTitle;
                toast.Content = toastMessage;
                toast.Show();

            }

        }

Thank you.

© Stack Overflow or respective owner

Related posts about c#

Related posts about windows-phone-7