简体   繁体   English

事件越来越多,一再被解雇

[英]Event being increasingly, repeatedly fired

I have an unusual thing happening with an RSS presenter I'm trying to make. 我正在尝试制作一个RSS演示者,这是个不寻常的事情。 It's meant to go to the next item after an 'Out' animation is played, then play the 'In' animation. 这意味着在播放“Out”动画后转到下一个项目,然后播放“In”动画。 http://oeis.org/A000217 http://oeis.org/A000217

        void _timer_Tick(object sender, EventArgs e)
    {
        Storyboard sbOut = this.FindResource("sbAnimateOut") as Storyboard;
        sbOut.Completed += new EventHandler(sbOut_Completed);
        sbOut.Begin();

    }

    void sbOut_Completed(object sender, EventArgs e)
    {
        if (_selected < _total)
        {
            _selected++;


        }
        else
        {
            GetFeed(_feed);
            _selected = 0;

        }
        lstbxItems.SelectedIndex = _selected;
        counter.Text = _selected.ToString();

        Storyboard sbIn = this.FindResource("sbAnimateIn") as Storyboard;
        sbIn.Begin();
    }

I noticed it seem to skip items though. 我注意到它似乎跳过了项目。 When I step through it line by line, it seems to execute the void sbOut_Completed(object sender, EventArgs e) once the first time, three times the second time, six times the third time - and so on, sequentially . 当我通过它一步逐行,似乎执行void sbOut_Completed(object sender, EventArgs e)一旦第一时间,第二时间三次,六次第三时间-等, 依次

Perhaps I'm going about this the wrong way and that's causing the issue? 也许我会以错误的方式解决这个问题并导致这个问题? Any suggestions? 有什么建议么?

You are adding another event handler every timer tick! 您正在每个计时器滴答添加另一个事件处理程

Move this code: 移动此代码:

sbOut.Completed += new EventHandler(sbOut_Completed);

into your initialization - only do it once. 进入初始化 - 只做一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM