简体   繁体   中英

Event being increasingly, repeatedly fired

I have an unusual thing happening with an RSS presenter I'm trying to make. It's meant to go to the next item after an 'Out' animation is played, then play the 'In' animation. 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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