Without answering the question, but as a workaround, you can just use int instead of bool, as C. does.
int m_IsFirstTime = 1; // 1 means true 0 means false. void SomeMethod() { if (1 == Interlocked.Exchange(ref m_IsFirstTime , 0)) // Do something for the first time. else // Do something for all other times. }
PS If there is evidence that reading is faster than writing, then Interlocked.CompareExchange may be better for this case (only once, and I accept many more than the first).
ILIA BROUDNO Jun 25 '14 at 17:25 2014-06-25 17:25
source share