protected DownloadInternal ( System.Action onScriptsDownloaded, System.Action onTimedOut ) : void | ||
onScriptsDownloaded | System.Action | Invoked when the scripts have completed downloading. |
onTimedOut | System.Action | Invoked when/if the operation times out (NB: 'onScriptsDownloaded' is never called if the operation times out). |
return | void |
protected void DownloadInternal(Action onScriptsDownloaded, Action onTimedOut)
{
// Setup initial conditions.
TimedOut = false;
IsLoading = true;
// Insert resources.
InsertCssLinks();
// TODO - Extend to include all resource types (images + CSS).
// Setup failure timeout.
DelayedAction timeout = new DelayedAction(DownloadTimeout, delegate
{
TimedOut = true;
IsLoading = false;
Helper.Invoke(onTimedOut);
});
timeout.Start();
// Download the scripts
DownloadScripts(delegate
{
if (!TimedOut) // Only invoke if the timeout hasn't elapsed before this callback.
{
Helper.Invoke(onScriptsDownloaded);
}
timeout.Dispose();
IsLoading = false;
});
}