如何确保涉及事件处理程序的数组是安全的(独占访问)? [英] How to make sure the array is safe (exclusive access) which involves Eventhandler?

查看:64
本文介绍了如何确保涉及事件处理程序的数组是安全的(独占访问)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,例如foo [1024].

I've an array, e.g. foo[1024].

我有一个事件处理程序,EventHandlerA,每当EventHandlerA被触发时,它都会将值写入foo数组.

I've an event handler, EventHandlerA, which WRITES values to foo array whenver EventHandlerA got fired.

在我的Main()中,我需要从foo数组中读取值.

In my Main(), I need to READ values out of foo array.

有没有办法对数组foo进行独占访问?

Is there a way to make the exclusive access of array foo?

即. EventHandlerA或Main()是否可以向foo写入数据或从foo读取数据,但不能同时进行?

ie. either EventHandlerA or Main() can write or read the data to/from foo but not the same time?

此外,一旦我在Main()中读取foo,我想在EventHandlerA可以在foo中写入新值之前刷新foo中的所有数据.

Also, once I read foo in Main(), I would like to flush all data in foo before EventHandlerA can write the new values in foo.

任何示例代码都会令人赞赏.

Any sample codes would be appreicated.

谢谢.

推荐答案

谁独享?

如果您指的是Private,那么它仅适用于每个对象,而不仅仅是数组.

If you mean Private then it is simply for every object, not only an array.

http://msdn.microsoft.com/en-us/library/st6sy9xe.aspx


这篇关于如何确保涉及事件处理程序的数组是安全的(独占访问)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆