2017-01-21 110 views
2

所以我在我的应用程序中使用线程。我想对我的部分代码进行基准测试,我发现代码在主线程上的运行速度明显加快了2-3倍。更改线程优先级 - Unity 3d

我想调整我创建的线程的线程优先级,但由于某些原因的优先级保持不变 - 总是最低。

代码:

public static void RunTest() 
    { 
     Thread thread = new Thread(Fun); 

     Debug.Log("thread.Priority before change: " + thread.Priority); 

     thread.Priority = System.Threading.ThreadPriority.Normal; 

     Debug.Log("thread.Priority after change:" + thread.Priority); 

     thread.Start(); 
    } 

    static void Fun() 
    { 
     Debug.Log("I am running on a separate thread!"); 
     Debug.Log("Current thread: " + Thread.CurrentThread.Priority); 
    } 

我总是得到 “最低” - 在所有3个案件。

如何更改线程的优先级团结?

回答

3

统一使用单声道的版本没有实现线程优先级

它现在在Mono 4.4实施,但这不是Mono Unity使用的版本。在他们将Mono版本升级到此版本之前,这根本行不通。