Search code examples
calendaruwpxamarin.formswindows-10-mobile

Windows 10 Phone Calendar on Cross Platform Project


I am trying to integrate device calendar into my Xamarin Forms application, however, in Windows 10 Mobile facing some serious issues! On the platform specific project for UWP I call the following native API:

var store = await Windows.ApplicationModel.Appointments.AppointmentManager.RequestStoreAsync(Windows.ApplicationModel.Appointments.AppointmentStoreAccessType.AppCalendarsReadWrite);

After calling the API, platform specific project throws this exception:

The message filter indicated that the application is busy. A COM call (IID: {638BB2DB-451D-4661-B099-414F34FFB9F1}, method index: 6) to an ASTA (thread 9840) appears deadlocked and was timed out.

I guess it has something to do with multi-threading and application domain! considering that I have given the calendar permission to the app, anyone has faced similar error ever before?

My Development Environment

  • Microsoft Visual Studio Community 2017

  • Version 15.1 (26403.7) Release

  • VisualStudio.15.Release/15.1.0+26403.7

  • Microsoft .NET Framework Version 4.7.02046

  • Visual Studio Tools for Universal Windows Apps 15.0.26403.07

  • Xamarin 4.4.0.34 (3f99c5a)


Solution

  • I have checked your project and reproduced the issue. You could solve the issue by replacing .Result with await keyword.

    Although async programming is relatively straightforward, there are some details to keep in mind which can prevent unexpected behavior.

    async methods need to have an await keyword in their body or they will never yield!

    This is important to keep in mind. If await is not used in the body of an async method, the C# compiler will generate a warning, but the code will compile and run as if it were a normal method. Note that this would also be incredibly inefficient, as the state machine generated by the C# compiler for the async method would not be accomplishing anything.

    For more detail please refer to Asynchronous programming.

    It is not recommend doing more logic code in the property's get method. So you could get your CalendarEvents in OnAppearing method just like following code.

    protected async override void OnAppearing()
    {
        base.OnAppearing();
        var events = await DependencyService.Get<ICalendar>(DependencyFetchTarget.GlobalInstance).GetEventsAsync();
    }