Arrays

barski

Junior Contributor
Joined
Apr 7, 2002
Messages
240
Location
Tennessee
What happens when a array of objects each of which have an event that is mapped to one method. for example, let's say i have an array of 10 Employee object. Each employee object has a ClockedIn Event that is mapped to one method. what happens when employee1, employee2, employee3 all clockin at the same time?
 
Sequentially or concurrently

The answer depends on what is meant by 'at the same time'. If the code handling employees clocking in (and therefore raising the event) were running in multiple threads, then the event handler might be executed concurrently in multiple threads. If the code were single threaded then the event handler would be executed sequentially for each employee. It all depends on the nature of the event source.

If you do not know the nature of the code which might raise the event, and do not wish the handler to be executed concurrently in multiple threads, then you must implement some synchronization checks, with lock in C# or SyncLock in VB.
 
Judging by the nature of your question, I think you would greatly benefit from a better understanding the concepts of program flow and threading. With the typical single-core single-CPU computer only one thing can happen at a time. Things can be done in a way that makes it seem like more than one thing can happen at a time, such as alternating between different tasks (threads) or doing tasks so quickly that they all seem to happen at once. Even with multiple CPUs/cores, a properly multi-threaded application probably wouldn't allow all employees to clock in at the same time, but instead it would probably make all other employees wait while it processed one at a time.
 
thanks for the input. it's all on a single thread. so what i gather from the info is that there is "something" within the framework that will prevent these items from executing concurrently or omitting one of the events.


As stated above it's on a single thread and it is really an array of FileSystemWatcher which has some way of constantly monitoring the files.
 
FileSystemWatcher documentation

The documentation for FileSystemWatcher states that, to avoid missing file system events, the handler code should be kept as short as possible (amongst other things). This indicates that the FileSystemWatcher raises events in a single-threaded manner, one event at a time.

It also suggests increasing the buffer size with the InternalBufferSize property, and avoid watching files with long file names.

Good luck :)
 
thanks for the input. it's all on a single thread. so what i gather from the info is that there is "something" within the framework that will prevent these items from executing concurrently or omitting one of the events.

It is the nature of single processor systems that only a single instruction can be executing at any one time. They take a very short amount of time so you can do lots of them together meaning that to slow moving things like people it can _look_ like there are multipe things happening at once. There aren't. One thing at a time on single processor systems, always. If you don't understand this then you need to, it is important and you're not going to use threading effectively or possibly even correctly until you do.
 
Back
Top