本文整理汇总了C#中System.Net.WebClient.OpenReadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.OpenReadAsync方法的具体用法?C# WebClient.OpenReadAsync怎么用?C# WebClient.OpenReadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.OpenReadAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getpage
private void getpage(string inputurl)
{
var webClient = new WebClient();
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
if (appSettings.Contains("BService") && !((bool)appSettings["BService"]))
{
webClient.OpenReadAsync(new Uri("http://v.gd/create.php?format=simple&callback=myfunction&url=" + inputurl + "&logstats=1" + DateTime.Now));
}
else webClient.OpenReadAsync(new Uri("http://is.gd/create.php?format=simple&callback=myfunction&url=" + inputurl + "&logstats=1" + DateTime.Now));
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadComplete);
}
示例2: ImageResultLoadedCallback
private void ImageResultLoadedCallback(IAsyncResult ar)
{
var imageQuery = (DataServiceQuery<Bing.ImageResult>)ar.AsyncState;
var enumerableImages = imageQuery.EndExecute(ar);
var imagesList = enumerableImages.ToList();
if (imagesList.Count == 0)
{
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("No results");
});
return;
}
RowNow = 0;
ColumnNow = 0;
foreach (var image in imagesList)
{
WebClient wc = new WebClient();
int cs = currentSearch;
wc.OpenReadCompleted += (s, args) =>
{
wc_OpenReadCompleted(s, args, cs);
};
wc.OpenReadAsync(new Uri(image.MediaUrl), wc);
}
}
示例3: DocumentExplorer
public DocumentExplorer()
{
InitializeComponent();
var documentsUri = new Uri(HtmlPage.Document.DocumentUri, "Documents/Documents.xml");
var client = new WebClient();
client.OpenReadCompleted += (o, e) => {
if (!e.Cancelled) {
if (e.Error != null) {
ErrorWindow.ShowError(e.Error);
}
else {
using (e.Result) {
var doc = XDocument.Load(e.Result, LoadOptions.None);
var docs = from document in doc.Descendants("Document")
select new DocumentInfo() {
Name = (string)document.Attribute("Name"),
Description= (string)document.Attribute("Description"),
OriginalLocation = new Uri(documentsUri, (string)document.Attribute("Name")),
XpsLocation = new Uri(documentsUri, (string)document.Attribute("XpsLocation"))
};
this.documents.ItemsSource = docs;
}
}
}
};
client.OpenReadAsync(documentsUri);
}
示例4: LoadRSS
protected void LoadRSS(string uri)
{
WebClient wc = new WebClient();
wc.OpenReadCompleted += wc_OpenReadCompleted;
Uri feedUri = new Uri(uri, UriKind.Absolute);
wc.OpenReadAsync(feedUri);
}
示例5: DownloadData
public static byte[] DownloadData(this WebClient webClient, Uri uri)
{
byte[] data = null;
try
{
var manualReset = new ManualResetEvent(false);
var client = new WebClient();
client.OpenReadCompleted += (o, e) =>
{
if (e.Error == null)
{
data = e.Result.ReadToEnd();
}
manualReset.Set();
};
client.OpenReadAsync(uri);
manualReset.WaitOne(TIMEOUT);
}
catch (WebException e)
{
//Do nothing, return null
}
return data;
}
示例6: btnCidade_click
private void btnCidade_click(object sender, RoutedEventArgs e)
{
WebClient client = new WebClient();
client.OpenReadCompleted +=client_OpenReadCompleted;
client.OpenReadAsync(new Uri("http://precosmarcenaria.herokuapp.com/cities.xml?q="+txtCidade.Text, UriKind.Absolute));
txtBCidade.Text = "Procurando cidades...Por Favor, aguarde";
}
示例7: LogIn
public static Boolean LogIn(string userName, string password)
{
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(authUser_OpenReadCompletedEventArgs);
webClient.OpenReadAsync(new Uri(""));
return authentification;
}
示例8: DownloadFile
public Task<Stream> DownloadFile(Uri url)
{
var tcs = new TaskCompletionSource<Stream>();
var wc = new WebClient();
wc.OpenReadCompleted += (s, e) =>
{
if (e.Error != null)
{
tcs.TrySetException(e.Error);
return;
}
else if (e.Cancelled)
{
tcs.TrySetCanceled();
return;
}
else tcs.TrySetResult(e.Result);
};
wc.OpenReadAsync(url);
MessageBoxResult result = MessageBox.Show("Started downloading media. Do you like to stop the download ?", "Purpose Color", MessageBoxButton.OKCancel);
if( result == MessageBoxResult.OK )
{
progress.HideProgressbar();
wc.CancelAsync();
return null;
}
return tcs.Task;
}
示例9: Download
public void Download()
{
var client = new WebClient();
var uri = new Uri("http://localhost/MediaInTheCloud.Host/Home/GetServerItems");
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(uri);
}
示例10: Download
//public void Save(string imageUrl)
//{
// ThreadPool.QueueUserWorkItem(GetImage, imageUrl);
//}
private void Download(string imageUrl, string imageName, Action<BitmapImage> callBack, string imageSaveName)
{
var imageUri = new Uri(string.Format(imageUrl, imageName));
var client = new WebClient();
client.OpenReadCompleted += (s, e) =>
{
try
{
var streamResourseInfo = new StreamResourceInfo(e.Result, null);
var streamReader = new StreamReader(streamResourseInfo.Stream);
byte[] imageBytes;
using (var binaryReader = new BinaryReader(streamReader.BaseStream))
{
imageBytes = binaryReader.ReadBytes((int)streamReader.BaseStream.Length);
}
string name = imageSaveName ?? imageName;
using (var stream = _isolatedStorageFile.CreateFile(name))
{
stream.Write(imageBytes, 0, imageBytes.Length);
var image = new BitmapImage();
image.SetSource(stream);
callBack.Invoke(image);
}
}
catch (Exception ex)
{
// Let it fail if not something catastrophic
if (!(ex is WebException))
throw;
}
};
client.OpenReadAsync(imageUri, client);
}
示例11: MyMap_MouseClick
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
MapPoint geographicPoint = _mercator.ToGeographic(e.MapPoint) as MapPoint;
string SOEurl = "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat";
SOEurl += string.Format(System.Globalization.CultureInfo.InvariantCulture, "?lon={0}&lat={1}&f=json", geographicPoint.X, geographicPoint.Y);
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += (s, a) =>
{
var sr = new StreamReader(a.Result);
string str = sr.ReadToEnd();
JObject jsonResponse = JObject.Parse(str);
double elevation = (double)jsonResponse["elevation"];
a.Result.Close();
MyInfoWindow.Anchor = e.MapPoint;
MyInfoWindow.Content = string.Format("Elevation: {0} meters", elevation.ToString("0"));
MyInfoWindow.IsOpen = true;
};
webClient.OpenReadAsync(new Uri(SOEurl));
}
示例12: detect
private IObservable<string> detect(string text)
{
var subject = new AsyncSubject<string>();
string detectUri = String.Format(GetDetectUri(text), appId, HttpUtility.HtmlEncode(text));
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler((obj, args) =>
{
if (args.Error != null)
{
subject.OnError(args.Error);
}
else
{
if (!args.Cancelled)
{
var xdoc = XDocument.Load(args.Result);
subject.OnNext(xdoc.Root.Value);
}
subject.OnCompleted();
}
});
wc.OpenReadAsync(new Uri(detectUri));
return subject;
}
示例13: GetRssFromTutBy
public static void GetRssFromTutBy(Object stateInfo)
{
Uri serviceUri = new Uri("http://news.tut.by/rss/index.rss");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
示例14: CacheImage
private static void CacheImage(object input)
{
// extract the url and BitmapImage from our intput object
var items = (KeyValuePair<string, BitmapImage>)input;
var url = items.Key;
var image = items.Value;
var cacheFile = SetName(items.Key);
var waitHandle = new AutoResetEvent(false);
var fileNameAndWaitHandle = new KeyValuePair<string, AutoResetEvent>(cacheFile, waitHandle);
var wc = new WebClient();
wc.OpenReadCompleted += OpenReadCompleted;
// start the caching call (web async)
wc.OpenReadAsync(new Uri(url), fileNameAndWaitHandle);
// wait for the file to be saved, or timeout after 5 seconds
waitHandle.WaitOne(5000);
if (s.FileExists(cacheFile))
{
// ok, our file now exists! set the image source on the UI thread
Deployment.Current.Dispatcher.BeginInvoke(() => image.SetSource(s.StreamFileFromIsoStore(cacheFile)));
}
}
示例15: GetUserLoginIdAndMemberGroups
/// <summary>
/// Gets current login user id and user's member groups
/// </summary>
public void GetUserLoginIdAndMemberGroups()
{
string uriString = Constants.InitParams.UserLoginIdHelperUrl(mainPage);
WebClient wcUserLogin = new WebClient();
wcUserLogin.OpenReadCompleted += new OpenReadCompletedEventHandler(wcUserLogin_OpenReadCompleted);
wcUserLogin.OpenReadAsync(new Uri(uriString));
}