問題在哪裏?VolatileWrite booleans
bool stillSingleClick = false;
// does not compime
System.Threading.Thread.VolatileWrite(ref stillSingleClick, true);
爲 'System.Threading.Thread.VolatileWrite(REF 對象,對象)' 的最佳重載的方法匹配具有一些無效 參數
爲什麼我問。我嘗試按以下方式區分我的doubleClick:
volatile bool stillSingleClick = false;
void SegmentLine_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
SegmentLine line = sender as SegmentLine;
if (e.ClickCount == 1)
{
stillSingleClick = true;
Thread thread = new Thread(
new System.Threading.ThreadStart(
delegate()
{
line.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
Thread.Sleep(System.Windows.Forms.SystemInformation.DoubleClickTime * 2);
if (stillSingleClick) // HERE ALWAYS TRUE!!!
{
SelectSegmentLine(line);
}
stillSingleClick = false;
}
));
}
));
thread.Start();
}
else if (e.ClickCount == 2)
{
stillSingleClick = false; // HERE SHOULD BE SET IN FALSE !!!
DisplaySegmentLineInfo(line);
}
}
不起作用stillSingleClick
始終爲真...
更新說明與易變的字段 – serhio 2010-11-22 15:37:26
+1 @cdhowie是的,它使用整數感覺不對,但我必須偶爾做同樣的事情。如果你必須有const和False的感覺,那麼你會覺得更笨拙:) – 2010-11-22 15:43:15
那麼,爲什麼你不使用像Jon這樣的易變的布爾值呢? – serhio 2010-11-22 17:09:43