I have the following code that I use to simulate a live data transfer, which simultaneously sends a message saying that each object of the Symbol type in the collection inside the Portfolio. Symbols should respond (in a different way, doing some work on it).
In order for this to be true at the same time, I am trying to register anonymous event handlers as follows:
static public void RegisterEvents() { foreach (Symbol symbol in Portfolio.Symbols) { GenerateQuoteRequest += () => { SomeMethod(symbol); }; } } static public void Run() { OnGenerateQuoteRequest(); Thread.Sleep(100); } public delegate void OnGenerateQuoteRequestEventHandler(); public static event OnGenerateQuoteRequestEventHandler GenerateQuoteRequest = delegate {}; ...
Then I try to raise this event, hoping that I will get several instances of "SomeMethod". Unfortunately, only the last character added is called.
What am I missing here?
source share