You can use the method Task.Delay():
loading.IsActive = true;
await Task.Delay(5000);
loading.IsActive = false;
When using this method, your user interface does not freeze.
Edit
In a more readable way, IMO would not pass milliseconds as a parameter, as in the example above. But instead pass the instance TimeSpan:
await Task.Delay(TimeSpan.FromSeconds(5));