Je ne sais pas ce que je fais mal:C# - champ de classe est nulle quand on y accède à partir d'un thread de travail, mais pas thread principal
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
}
}