C# XNA中的阻塞函数

C# XNA中的阻塞函数,c#,xna,C#,Xna,我目前正在XNA中编写一个RPG引擎。引擎执行一系列脚本命令,但必须阻止,直到下一个脚本命令。我该怎么做 例如: // interact with an NPC named in String 'Name' String interactfunc = String.Format("{0}_Interact", Name); System.Reflection.MethodInfo info = Factory.Script.GetType().GetMethod(interactfunc); i

我目前正在XNA中编写一个RPG引擎。引擎执行一系列脚本命令,但必须阻止,直到下一个脚本命令。我该怎么做

例如:

// interact with an NPC named in String 'Name'
String interactfunc = String.Format("{0}_Interact", Name);
System.Reflection.MethodInfo info = Factory.Script.GetType().GetMethod(interactfunc);
if (info != null) info.Invoke(Factory.Script, new object[]{this});

//this may run the following script command for NPC 'Bob'

    public void Bob_Interact(NPC Bob)
    {
        Bob.Say("Well this worked.");
        Bob.Say("Didnt it?");
    }

//the say command looks like this

    public void Say(String Text)
    {
        TalkGui gui = new TalkGui(this, Text);


        Factory.Game.Guis.Add(gui);
        Factory.FocusedGui = gui;

    }
现在我需要这个脚本,在运行下一个脚本命令之前,等待第一个TalkGui被关闭


最好的方法是什么?可能在自己的线程中运行脚本函数或其他什么?

您不想在这种情况下使用线程。它们太重了

你真正想要的是合作。您可以使用
yield
和迭代器在C#中模拟这些

这里有一些例子和例子。也许我的答案也值得一读

C#5.0引入了一种更好的异步编程方法。和