使用XNA 3.1进行慢速线程处理

时间:2012-09-09 15:21:04

标签: c# multithreading performance xna

我在XNA中遇到一个非常奇怪的问题。我正在使用Q9400的PC上工作。

以下代码是在XNA的Update()函数中启动的。

        Stopwatch sw = new Stopwatch();

        Thread[] threads = new Thread[2];
        threads[0] = new Thread(() => Thread_UpdateDoodadsMovable(gameTime));
        threads[1] = new Thread(() => Thread_UpdateDoodadsRotated(gameTime));
        sw.Start();
        foreach (Thread t in threads)
        {
            t.Start();
        }
        foreach (Thread t in threads)
        {
            t.Join();
        }

        sw.Stop();
        Console.WriteLine("A " + sw.ElapsedTicks);
        sw.Reset();

当代码被注释时,两个线程现在都是“空”:

    public void Thread_UpdateDoodadsRotated(GameTime gametime)
    {
        // level.UpdateDoodadsRotated(gameTime);
    }
    public void Thread_UpdateDoodadsMovable(GameTime gametime)
    {
       // level.UpdateDoodadsMovable(gametime);
    }

sw.ElapsedTicks在7000到10000之间返回。有人可以向我解释为什么会发生这种情况吗?

我知道创建线程而不是从ThreadPool中获取它们并不是性能最好的方法,但是线程创建比ElapsedTicks返回的时间少得多。

0 个答案:

没有答案