イベントを定義するクラスがあります。
public class EventRaiserUtility
{
public event EventHandler updateList;
public void updateListEvent()
{
if (updateList != null)
{
updateList(this, EventArgs.Empty);
}
}
public static EventRaiserUtility raiser = new EventRaiserUtility();
}
これが私のイベントを発生させる場所です:
EventRaiserUtility.raiser.updateListEvent();
そして最後に、これは私がリスナーを作成しようとしている場所です:
...
EventRaiserUtility.raiser.updateList += new EventHandler(raiser_updateList);
//placed in the init method of another class
...
private void raiser_updateList(object sender, EventArgs e)
{
connType = MainWindowViewModel.getTTC();
}
簡単に言えば、このイベントは、リストが更新されたときに通知し、別のリストを更新する必要がgetTTC()
ありraiser_updateList
ます。
しかし、raiser_updateList
呼び出されることはありません。なんで?私のコードの 3 つのスニペットはすべて 3 つの異なるクラス (同じプロジェクト) にありますが、これは問題ではありません。