更改线程优先级 - Unity 3d
Change thread priority - Unity 3d
所以我在我的应用程序中使用线程。我想对我的部分代码进行基准测试,我发现代码在主线程上的运行速度明显加快 - 快 2-3 倍。
我想调整我正在创建的线程的线程优先级,但由于某种原因优先级保持不变 - 总是最低。
代码:
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);
}
我总是得到 "lowest" - 在所有 3 种情况下。
如何在 unity 中更改线程优先级?
Unity 使用未实现 线程优先级.
的 Mono 版本
它现在在 Mono 4.4 中实现,但这不是 Mono Unity 使用的版本。在他们将他们的 Mono 版本升级到这个版本之前,这根本行不通。
所以我在我的应用程序中使用线程。我想对我的部分代码进行基准测试,我发现代码在主线程上的运行速度明显加快 - 快 2-3 倍。
我想调整我正在创建的线程的线程优先级,但由于某种原因优先级保持不变 - 总是最低。
代码:
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);
}
我总是得到 "lowest" - 在所有 3 种情况下。
如何在 unity 中更改线程优先级?
Unity 使用未实现 线程优先级.
的 Mono 版本它现在在 Mono 4.4 中实现,但这不是 Mono Unity 使用的版本。在他们将他们的 Mono 版本升级到这个版本之前,这根本行不通。