Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

async/await issue on Mac

$
0
0

Hi,

I'm just getting started and found a strange issue with asynchronous code. Try this in an iOS project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Portable;

namespace AsyncAwaitTest
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;
        AsyncAwaitTestViewController viewController;

        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            Test ().Wait ();

            window = new UIWindow (UIScreen.MainScreen.Bounds);

            viewController = new AsyncAwaitTestViewController ();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible ();

            return true;
        }

        public static async Task Test()
        {
            await Task.FromResult (true);
            await Task.Delay (1000);
            await Task.FromResult (true);
        }
    }
}

It seems that the await Task.Delay immediately returns without delay and causes control to pass back to the caller - the second call to await Task.FromResult is never even executed! I've tried both via the debugger and by doing Console.WriteLines to see which statement successfully execute. In both cases, it's clear something very wrong is happening when awaiting the delay. No exceptions, no weird application output.

Any ideas?

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>