locked
A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E) RRS feed

  • Question

  • This line give me the below error. Geopositionpos = awaitgeolocator.GetGeopositionAsync().AsTask(token);

    A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)

    I am tring to access the device coordinate in the back ground task. below is the code.

       async void IBackgroundTask.Run(IBackgroundTaskInstance taskInstance)
            {
                BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
                try
                {
                   // Associate a cancellation handler with the background task.
                    taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
    
                  // Get cancellation token
                    if (m_cts == null)
                    {
                        m_cts = new CancellationTokenSource();
                    }
                    CancellationToken token = m_cts.Token;
    
                    // Create geolocator object
                    Geolocator geolocator = new Geolocator();
    
                    // Make the request for the current position
                    Geoposition pos = await geolocator.GetGeopositionAsync().AsTask(token);
                  
                           
    
                    DateTime currrentTime = DateTime.Now;
    
                    WriteStatusToAppdata("Time: " + currrentTime.ToString());
                    WriteGeolocToAppdata(pos);
                }
                catch (UnauthorizedAccessException)
                {
                    WriteStatusToAppdata("Disabled");
                    WipeGeolocDataFromAppdata();
                }
                catch (Exception ex)
                {
                    WriteStatusToAppdata("Disabled");
                    WipeGeolocDataFromAppdata();
                }
                finally
                {
                    m_cts = null;
    
                    deferral.Complete();
                }
            }
    Any suggestion where I am doing wrong.
      i have used below link.

    http://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66/view/SourceCode#content

     

               

     

     

     

     

     


    http://www.abdulazizfarooqi.wordpress.com Abdul Aziz Farooqi [BizTalk & SharePoint Consultant] MCPD Web & MCPD SharePoint 2010



    Saturday, October 12, 2013 6:14 AM

Answers

  • You will always need to call GetGeopositionAsync() on the main UI thread (usually OnNavigatedTo is a good place), to ensure you get that initial prompt for location consent.

    Is this running on Windows 8 or 8.1?  Do you see your app has permission under the modern PC settings UI?  Swipe in from the right to get the charms bar, then go to Settings->Change PC Settings->Privacy->Location.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Proposed as answer by Dave SmitsMVP Saturday, October 19, 2013 7:57 PM
    • Marked as answer by Anne Jing Tuesday, October 29, 2013 9:25 AM
    Saturday, October 19, 2013 7:47 PM

All replies

  • Do you get the same error from the sample itself or only if you copy the code to your own app?

    Saturday, October 12, 2013 2:08 PM
    Moderator
  • No Sample is working perfect. I need to get the cordinate of the tablet.

    (1) i create one blank xaml project.

    (2) Add one WINRT for BackGround Task Project. 

    (3) Add the reference of WinRT to my project. 

    (4) Registre BackGroundTask.

    Everything is working fine, but wehnever i tried to initiate the Geolocaiton object it throws that eror. 

    In the Sample , Background task is register on the button clicck, but i need to register the Background task when app load. So i register the Task on NavigateTo event in the MainPage.xaml.

    Any link or help will be appreciated.


    http://www.abdulazizfarooqi.wordpress.com Abdul Aziz Farooqi [BizTalk & SharePoint Consultant] MCPD Web & MCPD SharePoint 2010


    Saturday, October 12, 2013 2:28 PM
  • do you have a project you can share with us? a demo one that shows the problem?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Saturday, October 12, 2013 2:30 PM
  • I got the issue btw, actually, i create one button, on the button event in the mainpage.xaml.cs i tried to access the geolocation position. Tablet ask me for permission, i press allow. after that my background task working fine just for 5 minutes. after 5 minutes same error in the background task, then i press client button again than both work fine. actually there is some permission issue in the back ground task to access the device. btw in the Packagemanifes capabilities i already checked the location , internet client and server.

    where i need to set the permission for background task to access the device. or what i am missing


    http://www.abdulazizfarooqi.wordpress.com Abdul Aziz Farooqi [BizTalk & SharePoint Consultant] MCPD Web & MCPD SharePoint 2010

    Saturday, October 12, 2013 3:18 PM
  • You will always need to call GetGeopositionAsync() on the main UI thread (usually OnNavigatedTo is a good place), to ensure you get that initial prompt for location consent.

    Is this running on Windows 8 or 8.1?  Do you see your app has permission under the modern PC settings UI?  Swipe in from the right to get the charms bar, then go to Settings->Change PC Settings->Privacy->Location.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Proposed as answer by Dave SmitsMVP Saturday, October 19, 2013 7:57 PM
    • Marked as answer by Anne Jing Tuesday, October 29, 2013 9:25 AM
    Saturday, October 19, 2013 7:47 PM