jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

CrossConnectivity.Current blocks the app on 100% loss #275

Closed rihadavid closed 8 years ago

rihadavid commented 8 years ago

This is a

Which plugin does this impact:

Version Number of Plugin: 2.1.2 Device Tested On: iPhone 4 / iOS 7.1.2 Simulator Tested On: iPhone 4s / iOS 8.1 (partially happening), iPhone 4s / iOS 9.3 (not happening)

Expected Behavior

CrossConnectivity.Current should always return the instance instantly (beacuse we cannot call it asynchronously)

Actual Behavior

Calling CrossConnectivity.Current on 100% loss connection (also probably wifi without the internet) takes up to 30 seconds to return, the slower device the longer time it takes. It's OK on iOS 9.3 simulator because it is fast, but terribly slow on iPhone 4 device.

If called from UI thread, it completely blocks the app until it returns.

Steps to reproduce the Behavior

  1. Create new sample one-screen iOS Xamarin App
  2. Add

    Console.WriteLine("FinishedLaunching 1");
    
    var current = CrossConnectivity.Current;
    
    Console.WriteLine("FinishedLaunching 2");

    to FinishedLaunching right before return true;

  3. Set link conditioner to 100% loss connection and enable it
  4. Launch the app in debug
  5. On iPhone 4 7.1.2 device the app will crash because it does not start in time, on IPhone 4S 8.1 simulator it will just extend the launching time
rihadavid commented 8 years ago

I've just found that if called inside await Task.Run(()=> it blocks my SQLite queries (or maybe all background code except UI?).

rihadavid commented 8 years ago

the hanging line is remoteHostReachability.TryGetFlags(out flags); inside RemoteHostStatus() .. this issue is also described on Xamarin Bugzilla

CR4567 commented 8 years ago

Same problem here. When connectivity drops, the complete app is freezing until connectivity is up again. Is there any solution or workaround?

jamesmontemagno commented 8 years ago

You should absolutely not put this in your FinishedLaunching. Add it to your ViewController or Xamarin.Forms Page.

This is a scenario that is not supported.