Issue
I have this code in Unity3D (using .Net 4x). in the async function i call to another function and this is never executed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
public class thread : MonoBehaviour
{
void Start()
{
DoTaskAsync();
}
public async void DoTaskAsync()
{
await Task.Run(() =>
{
doSomething();
});
}
}
The code runs perfectly in PC and do the job something. But when i build for Android and run in Android, i got no errors, but job something is not done.
Any idea about this, please? Thanks in advance.
Solution
You need to await the DoTaskAsync()
method where you call it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
public class thread : MonoBehaviour
{
void Start()
{
await DoTaskAsync();
}
public async void DoTaskAsync()
{
await Task.Run(() =>
{
doSomething();
});
}
}
Answered By - Chad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.