views:

299

answers:

1

How do you access an integer (increment nCount++) in the main form from the method of an asynchronous callback function?

I know that with methods you have to check if invoke is required, then call begininvoke for the intended method as a delegate, as to avoid an illegal threading operation, but how an you perform a simple operation such as nCount++ from another thread?

+4  A: 
Interlocked.Increment(ref variable);
Mehrdad Afshari
int result = Interlocked.Increment(ref variable);to read:int result = Interlocked.Read(ref variable);Good answer though. Upvote.
Jonathan C Dickinson