Does anyone have a good handle on the sequence of events when an event is raised and multiple classes are all subscribed to the event?
- Does each class get a copy of the argument?
- Does each class get a pointer/address/ref to the one and only argument?
- Do all the classes get the argument at once, or is passed in subscriber sequence as it falls out of scope?
- Can the classes each work independently (own thread) with the argument object, or does one have to complete and release the object so it can be passed to the next class in the order they subscribed.?
I have spent hours trying to find the official answer and either Microsoft won't cop to it, or I can't think of the right search terms.
Here's my situation:
I want to pass an arguments object that has a Bitmap, a string and couple other values each time a given event is raised.
Several other classes are subscribed to that event.
So one should process it and save it, one should email it, one should display it and so on. Every class works fine when it is the only class subscribed, but as more classes subscribe to the event the more often I get an "object in use" error randomly.
The kicker is that each class as soon as it gets the Event with argument, makes a low level clone of the argument and works with the clone. So I just can't figure out how each class with its own clone of the arguments can still be affected by another class with its own clone.
Maybe I'm not making a true clone?
Expand|Select|Wrap|Line Numbers
- public class StepArgs : EventArgs, ICloneable
- {
- private string message = string.Empty;
- private List<string> idlist = new List<string>();
- private Image photo = MyCoolProgram.Properties.Resources.TronBit;//Just a placeholder really
- private string filepath = string.Empty;
- public string Message
- {
- get { return message; }
- set { message = value; }
- }
- public List<string> IDlist = new List<string>();
- public Image Photo
- {
- get { return photo; }
- set { photo = value; }
- }
- public string FilePath
- {
- get { return filepath; }
- set { filepath = value; }
- }
- public override string ToString()
- {
- return "StepArgs";
- }
- public StepArgs()
- {
- IDlist.Add(string.Empty);
- //IDlist.Clear();
- Message = string.Empty;
- FilePath = string.Empty;
- Photo = ThrillCapture.Properties.Resources.Bit;
- }
- #region ICloneable Members
- public object Clone()
- {
- return (object)this.MemberwiseClone();
- }
- #endregion
- }