Hello,
Supposing I have a single class, containing a simple method. Let's say that there is a delegate with the same signature as this method.
I want to run multiple long-running processes, each one launched from this class. Each process contains an event, which is composed of multicast delegates of the same type as the delegate mentioned above. Once each "worker" class is instantiated, the "controlling" class, mentioned above, subscribes to the worker's event, with the same simple method mentioned above. Once each worker's job is complete, it's event is invoked.
In a single-threaded environment, this architecture is fairly straight-forward. However, I plan to run each worker process on a separate thread. Therefore, multiple worker's will invoke their events (almost) simultaneously, each one subscribed to by the controlling class's simple method.
Is there a guarantee, given that delegates are immutable, that each thread will have exclusive access to the simple method? I'm not concerned about locking code within the simple method, I'm concerned that Thread #1 will invoke the method with a set of parameters, and Thread #2 invokes the same method, at almost the same time.
Before Thread#1 enters the lock statement, can Thread #2 (which enters the method at almost the same time as Thread #2) overwrite the parameters specified by Thread #1, resulting in Thread #2's parameters effectively being processed twice?
I realise that this is a bit of a mouthful, I'd be delighted to provide more info.