Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Synchronized method always return false?

Tags:

In Windows Phone 8 (only on device!) try running this code:

public MainPage()
{
    InitializeComponent();

    var myTrue = GetTrue();
    Debug.WriteLine(myTrue);
    // false
}

[MethodImpl(MethodImplOptions.Synchronized)]
private static bool? GetTrue()
{
    return true;
}

You will see myTrue always is False! Why?! How it can be?!

UPDATE: Tested on devices: Nokia Lumia 920, HTC 8X, Nokia Lumia 925

like image 309
Roman Golenok Avatar asked Dec 13 '13 13:12

Roman Golenok


1 Answers

I think that kind of behavior is due to this:

Windows Phone

Specifying the Synchronized option for the MethodImplAttribute constructor is not supported and will not result in synchronized behavior.

Check it here http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.runtime.compilerservices.methodimploptions%28v=vs.105%29.aspx

like image 170
hmartinezd Avatar answered Nov 04 '22 06:11

hmartinezd