【发布时间】:2023-04-10 04:24:01
【问题描述】:
我不明白为什么 UnityWebRequest 构造函数没有在此回调中返回。是线程问题吗?
StreamReader streamReader = new StreamReader("C:\\file.txt");
streamReader.ReadToEndAsync().ContinueWith((task) => {
Debug.Log("read done");
UnityWebRequest request = new UnityWebRequest();
Debug.Log("web request created");
});
在 Unity 控制台中,我只看到“读取完成”消息。
【问题讨论】:
-
ContinueWith可能在后台线程上执行,UnityWebRequest的构造函数会抛出您在主线程中看不到的异常 => 后台任务静默失败 -
是的,这绝对是线程问题,但我找到了使用主线程的解决方案,谢谢
标签: c# unity3d asynchronous networking io