Skip to content

Commit f33004a

Browse files
committed
A HttpClient vs Webclient implementation
1 parent ec2d36f commit f33004a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlow/ImageClassification.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.IO;
33
using System.Linq;
44
using System.Net;
5+
using System.Net.Http;
56
using System.Text;
7+
using System.Threading.Tasks;
68
using ICSharpCode.SharpZipLib.GZip;
79
using ICSharpCode.SharpZipLib.Tar;
810
using Microsoft.ML;
@@ -113,10 +115,18 @@ class OutputScores
113115

114116
private static string Download(string baseGitPath, string dataFile)
115117
{
118+
#if false
116119
using (WebClient client = new WebClient())
117120
{
118121
client.DownloadFile(new Uri($"{baseGitPath}"), dataFile);
119122
}
123+
#else
124+
var httpClient = new HttpClient();
125+
using (var file = File.OpenWrite(dataFile))
126+
{
127+
httpClient.GetStreamAsync(baseGitPath).ContinueWith((Task<Stream> t) => t.Result.CopyToAsync(file));
128+
}
129+
#endif
120130

121131
return dataFile;
122132
}

0 commit comments

Comments
 (0)