Webpage freeze with WaitForCompletion()

Hi,
When using WaitForCompletion() and build Webgl, webpage freeze with no error showing.
Works fine on Editor.
Tried 2019 to 2020 with addressable 1.17.17 to 1.18.4 allways freezing just when I add WaitForCompletion() on my code.
Here the code. Any help??

public static Material CreateDoorMat(string cs)
{
    string[] Code=cs.Split("&"[0]);
    string color=Code[1];
    GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true);

    var handle = Addressables.LoadAssetAsync<Texture2D>(Code[1]);
    Texture2D T=handle.WaitForCompletion();
        
    Material mata=new Material(Shader.Find("Standard"));
    mata.SetTexture("_MainTex", T);
    GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(false);
    Addressables.Release(handle);
    return mata; 
}

Thanks,

Yes, of course it does because websites are single threaded. There is no way to wait for an asynchronous operation synchronously. Because you are freezing the main thread of your website, the operation can never finish. You can only use coroutines in such cases and work with callbacks. Without a coroutine activating your “loading circle” also has no effect since, again, you’re freezing the execution inside this method. So there is no way to draw the next frame. Apart from that your use of GameObject.Find should be optimised and is also lacking error checking. You do 3 blind reference accesses in one line and each one could fail.

So you should use a coroutine just like in the example in the docs. It’s not clear how or where you use this method, so it’s impossible to show you how it should be changed.

Hi, Thanks for the answer.
As in unity document.
The AsyncOperationHandle.Task property is not available on WebGL as multi-threaded operations are not supported on that platform.

I will do it with coroutine with callbacks,

Thanks,