[英]Why does the Synchronized method always return false?
In Windows Phone 8 (only on device !) try running this code: 在Windows Phone 8中(仅在设备上 !)尝试运行此代码:
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 ! 你会看到
myTrue
永远是假的! Why?! 为什么?! How it can be?!
它怎么样?!
UPDATE : Tested on devices: Nokia Lumia 920, HTC 8X, Nokia Lumia 925 更新 :在设备上测试:诺基亚Lumia 920,HTC 8X,诺基亚Lumia 925
I think that kind of behavior is due to this: 我认为这种行为是由于这个原因:
Windows Phone
Windows Phone
Specifying the Synchronized option for the MethodImplAttribute constructor is not supported and will not result in synchronized behavior.
不支持为MethodImplAttribute构造函数指定Synchronized选项,并且不会导致同步行为。
Check it here http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.runtime.compilerservices.methodimploptions%28v=vs.105%29.aspx 在这里查看http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.runtime.compilerservices.methodimploptions%28v=vs.105%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.