C# EventHandler未启动

C# EventHandler未启动,c#,.net,winforms,events,C#,.net,Winforms,Events,在一个我一直在做的练习项目中,我在获取最后的细节时遇到了一些问题。该应用程序是一个卡片组,它被洗牌并分配适当的图像,然后我们可以将它们放在屏幕上。当甲板是空的一个事件应该火,但我不能让它火,不知道我错过了什么。Deck.cs是publisher,Form1是listener。使用标准事件参数 Deck.cs: public event EventHandler<EventArgs> EndOfDeck; public Card Draw() { FindAce aceFou

在一个我一直在做的练习项目中,我在获取最后的细节时遇到了一些问题。该应用程序是一个卡片组,它被洗牌并分配适当的图像,然后我们可以将它们放在屏幕上。当甲板是空的一个事件应该火,但我不能让它火,不知道我错过了什么。Deck.cs是publisher,Form1是listener。使用标准事件参数

Deck.cs:

public event EventHandler<EventArgs> EndOfDeck;

public Card Draw()
{
    FindAce aceFound;
    EventArgs emptyDeck;

    if (_cards.Count != 0)
    {
        Card card = _cards[0];
        _cards.RemoveAt(0);

        if (card.FaceVal == FaceValue.Ace)
        {
            switch (card.Suit)
            {
                case Suit.c:
                    aceFound = new FindAce("Cloves");
                    AceFound(aceFound);
                    break;
                case Suit.d:
                    aceFound = new FindAce("Diamonds");
                    AceFound(aceFound);
                    break;
                case Suit.h:
                    aceFound = new FindAce("Hearts");
                    AceFound(aceFound);
                    break;
                case Suit.s:
                    aceFound = new FindAce("Spades");
                    AceFound(aceFound);
                    break;
            }
        }

        return card;
    }
    else
    {
        emptyDeck = new EventArgs();
        EmptyDeck(emptyDeck);

        return null;
    }
}

public void EmptyDeck(EventArgs e)
{
    if (EndOfDeck != null)
        EndOfDeck(this, e);
}

不过,我的另一个事件是在找到王牌时启动的,没有任何问题。有点累了,我可能错过了一些非常愚蠢的事情。。感谢您的帮助

未触发
EmptyDeck
事件,因为您的表单代码已在绘图之前检查牌组中是否有卡:

while (TheDeck._Cards.Count != 0)
{
    newCard = TheDeck.Draw();

您可以使用,而不是创建新的EventArgsHanks,将内容检查移到Deck.cs中,并使其正常工作,感谢您提供有关EventArgs.Empty的提示!
while (TheDeck._Cards.Count != 0)
{
    newCard = TheDeck.Draw();