当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.OpenReadAsync方法代码示例

本文整理汇总了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);
        }
开发者ID:svaithia,项目名称:Quick.Short-WP7,代码行数:14,代码来源:MainPage.xaml.cs

示例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);
            }
        }
开发者ID:tiagobabo,项目名称:windows-phone-gallery,代码行数:30,代码来源:BingSearch.xaml.cs

示例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);
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:31,代码来源:DocumentExplorer.xaml.cs

示例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);
 }
开发者ID:Esri,项目名称:arcgis-samples-winphone,代码行数:7,代码来源:GeoRSS.xaml.cs

示例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;
        } 
开发者ID:Smeedee,项目名称:Smeedee-Mobile,代码行数:26,代码来源:WebClientDownloadDataExtension.cs

示例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";
 }
开发者ID:otavioschwanck,项目名称:precos_marcenaria_windows_phone,代码行数:7,代码来源:MainPage.xaml.cs

示例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;
 }
开发者ID:socloc,项目名称:socloc_servlet_based,代码行数:7,代码来源:DatabaseHandler.cs

示例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;
 }
开发者ID:praveenmohanmm,项目名称:PurposeColor_Bkp_Code,代码行数:28,代码来源:WinMediaDownloader.cs

示例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);
 }
开发者ID:kindohm,项目名称:silverlight-app-does-what,代码行数:7,代码来源:ServerMonitor.cs

示例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);
        }
开发者ID:Microsoft1080,项目名称:battlelogmobile,代码行数:39,代码来源:ImageRepository.cs

示例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));
        }
开发者ID:Esri,项目名称:arcgis-samples-winphone,代码行数:25,代码来源:SOEElevationLatLonJsonObject.xaml.cs

示例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;
        }
开发者ID:joeldart,项目名称:RX-Example,代码行数:25,代码来源:MainPage.xaml.cs

示例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);
 }
开发者ID:apunko,项目名称:RssNewsFromTutBy,代码行数:7,代码来源:Program.cs

示例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)));
            }

        }
开发者ID:wuchangqi,项目名称:ifixit-microsoft,代码行数:29,代码来源:ImageCacher.cs

示例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));
 }
开发者ID:nilavghosh,项目名称:VChk,代码行数:10,代码来源:UserAccessHandler.cs


注:本文中的System.Net.WebClient.OpenReadAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。