Not sure what I'm doing wrong:
class MyClass
{
private EventInfo eventInfo;
public void OnGenerateEvent(object sender, EventArgs e)
{
// Called from *main* thread
// Load assembly and set eventInfo here
eventInfo = ....GetEvent(...);
eventInfo.AddEventHandler(source, handler);
// Call to a static method in another assembly
someMethodInfo.Invoke(null, null);
}
public void OnEventChanged(object sender, EventArgs args)
{
// Called from a *worker* thread created
// by that static method in the other assembly
eventInfo is null here !
// Trying to remove handler
eventInfo.RemoveEventHandler(.....);
}
// But...
protected override void Dispose(bool disposing)
{
// Called from *main* thread when program closes
eventInfo is *not* null here
}
}