0

事件处理程序委托如何删除自己?

像这样的代码

    void timerTick(object sender, EventArgs e)
    {
        if (!IsHolding){
            return;
        }

        UtilityStoryboardManager.PlayerStoryboard("End", (_) =>{
            IsHolding = false;
            //call some function or  perform some logic
            timer.Stop();
            //How Can a eventhandler delegate remove itself ??
            //timer.Tick -= timerTick;
        }, null);
  }
4

1 回答 1

0

你想做这样的事情吗?

void timerTick(object sender, EventArgs e)
{
    if (!IsHolding){
        return;
    }

    UtilityStoryboardManager.PlayerStoryboard("End", (_) =>{
        IsHolding = false;
        //call some function or  perform some logic
        timer.Stop();
        //How Can a eventhandler delegate remove itself ??
        //timer.Tick -= timerTick;
    }, null);
 (sender as Timer).Tick-=timerTick; // removes the event
}
于 2013-08-20T01:47:25.210 回答