Bug 16679 - Android.App.SyncContext.Post works strange
Summary: Android.App.SyncContext.Post works strange
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.10.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-12-09 12:12 UTC by Grigory (Playtika)
Modified: 2013-12-11 15:13 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Grigory (Playtika) 2013-12-09 12:12:30 UTC
If called from UI thread it does simple Send. Why ?

Post should be Asynchronous. And whether we are on UI thread or not - shouldn't change the asynchronous nature of Post.
Action should be added to queue and executed when current event loop iteration has completed.

Code:
public override void Post(SendOrPostCallback d, object state)
{
    <Post>c__AnonStorey28 storey = new <Post>c__AnonStorey28 {
        d = d,
        state = state
    };
    Looper mainLooper = Looper.MainLooper;
    if (Looper.MyLooper() == mainLooper)
    {
        storey.d(storey.state);
    }
    else
    {
        using (Handler handler = new Handler(Application.Context.MainLooper))
        {
            handler.Post(new Action(storey.<>m__19));
        }
    }
}
Comment 1 Grigory (Playtika) 2013-12-09 12:17:54 UTC
Have a look at Post method in Android looper, or in Windows Forms/WPF Synchronization contexts. They work correctly. They don't inline anything in POST.
Comment 2 Grigory (Playtika) 2013-12-11 05:32:24 UTC
This logic breaks Task.Yield which does post on current context. But instead of that it calls continuation synchronously
Comment 3 Jonathan Pryor 2013-12-11 15:13:41 UTC
Fixed in monodroid/17a569db.