"&To=" + Uri.EscapeDataString("'" + _to + "'") +
"&$format=Raw";
- var client = new WebClient();
- client.Credentials = new NetworkCredential(ApplicationSettings.AzureMarketplaceKey, ApplicationSettings.AzureMarketplaceKey);
- client.Encoding = Encoding.UTF8;
-
- try
+ using (var client = new OTWebClient())
{
- var content = client.DownloadString(apiurl);
+ client.Credentials = new NetworkCredential(ApplicationSettings.AzureMarketplaceKey, ApplicationSettings.AzureMarketplaceKey);
+ client.Encoding = Encoding.UTF8;
- buf = Regex.Replace(content, @"^<string[^>]*>(.*)</string>$", "$1");
- return true;
- }
- catch (WebException)
- {
- buf = null;
- return false;
+ try
+ {
+ var content = client.DownloadString(apiurl);
+
+ buf = Regex.Replace(content, @"^<string[^>]*>(.*)</string>$", "$1");
+ return true;
+ }
+ catch (WebException)
+ {
+ buf = null;
+ return false;
+ }
}
}
}
}
- public void Dispose()
+ protected virtual void Dispose(bool disposing)
{
if (this.disposed) return;
- this.CancelAsync();
-
- lock (this.lockObject)
+ if (disposing)
{
- foreach (var item in this.innerDictionary)
- item.Value.Dispose();
+ this.CancelAsync();
- this.innerDictionary.Clear();
- this.cancelTokenSource.Dispose();
+ lock (this.lockObject)
+ {
+ foreach (var item in this.innerDictionary)
+ item.Value.Dispose();
+
+ this.innerDictionary.Clear();
+ this.cancelTokenSource.Dispose();
+ }
}
}
+
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ~ImageCache()
+ {
+ this.Dispose(false);
+ }
}
}
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
return loadImageTask.ContinueWith(t => {
+ client.Dispose();
+
if (t.IsFaulted) throw t.Exception;
return MemoryImage.CopyFromBytes(t.Result);
if (this.memoryImage != null)
this.memoryImage.Dispose();
+
+ if (this.loadAsyncCancelTokenSource != null)
+ this.loadAsyncCancelTokenSource.Dispose();
}
}
}