How do you access an integer (increment nCount++) in the main form from the method of an asynchronous callback function?
如何从异步回调函数的方法访问主窗体中的整数(增量nCount ++)?
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?
我知道使用方法你必须检查是否需要调用,然后调用begininvoke作为委托的目标方法,以避免非法的线程操作,但是如何从另一个线程执行简单的操作,如nCount ++?
1 个解决方案
#1
Interlocked.Increment(ref variable);
#1
Interlocked.Increment(ref variable);