'Why Unity game freezes when switching resolution and full screen?

I wrote switching full-screen and resolution method in UI events . The codes are down here .

//ui[index] is GameObject.
ui[2].GetComponent<Toggle>().onValueChanged.AddListener(full =>Screen.fullScreen=full);

I changed the following settings . This is a picture of it . Player Settings

So I built it and switched full-screen mode only , successfully but incompletely .

UI elements were being stretched , screen was frozen but audio still playing . I can't take a screenshot because I must reactive screen to make it normal .

I don't figure out how this could be happened . Even though I put my code into main thread , it was also happened .

private void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        Screen.fullScreen = !Screen.fullScreen;
    }
}

I can add more useful information if necessary . Any help is greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source