【问题标题】:Unity: Hololens wont run thread when deployed but works in editorUnity:Hololens 在部署时不会运行线程但在编辑器中工作
【发布时间】:2020-06-29 05:56:04
【问题描述】:

我正在尝试在 Hololens 上发送 UDP 广播,但由于某种原因线程不会被执行。有趣的是,当我在 VS 中的旧笔记本电脑上编译它时,它可以工作吗?!我比较了安装的 SDK,设置了所有内容,但是当我在旧笔记本电脑上编译它时,我无法弄清楚为什么它会起作用。我最初发现这只是一个巧合。

这会调用线程:

public void StartThread()
{
    // create thread for reading UDP messages
    readThread = new Thread(new ThreadStart(ReceiveData));
    readThread.IsBackground = true;
    readThread.Start();       
}

线程看起来像这样:

private void ReceiveData()
{
    client = new UdpClient(port);
    client.EnableBroadcast = true;
    Debug.Log("Thread Started");
    while (true)
    {
        try
        ....

调试行甚至不会被执行。我在 Unity 中工作,但不在 Hololens 上工作,除了我在我的旧机器上编译它。

有什么想法吗?我在这里完全不知所措。

【问题讨论】:

  • 您尝试debugging 与附加的调试器并设置断点吗?您是否也尝试仅使用... = new Thread(ReceiveData);
  • 谢谢你,新线程(ReceiveData);那成功了。然而,为什么它在另一台部署机器上工作是没有意义的。
  • 是的 Beginning in version 2.0 of the .NET Framework, it is not necessary to create a delegate explicitly. Specify the name of the method in the Thread constructor, and the compiler selects the correct delegate. 但正如你所说,它的行为实际上应该和我猜的一样。

标签: visual-studio unity3d uwp udp hololens


【解决方案1】:

正如derHugo建议的那样,线程需要像这样启动

public void StartThread()
{
    // create thread for reading UDP messages
    readThread = new Thread(ReceiveData);
    readThread.IsBackground = true;
    readThread.Start();       
}

成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2021-11-11
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多