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


C# System.Net.WebClient.DownloadDataAsync方法代码示例

本文整理汇总了C#中System.Net.WebClient.DownloadDataAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.DownloadDataAsync方法的具体用法?C# System.Net.WebClient.DownloadDataAsync怎么用?C# System.Net.WebClient.DownloadDataAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了System.Net.WebClient.DownloadDataAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Urldown_DownloadDataCompleted

        public static void Urldown_DownloadDataCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null || e.Result.Length <= 0 || e.Cancelled)
            {
                return;
            }
            var resultstr = e.Result;
            if (string.IsNullOrEmpty(resultstr)) return;

            var tag = SearchData.JieXiData(resultstr);
            if (tag == null) return;
            if (!string.IsNullOrEmpty(tag.Img))
            {
                using (
                    var imgdown = new System.Net.WebClient
                        {
                            Encoding = System.Text.Encoding.UTF8,
                            Proxy = PublicStatic.MyProxy
                        })
                {
                    imgdown.DownloadDataAsync(new System.Uri(tag.Img), tag);
                    imgdown.DownloadDataCompleted += SearchImg.Imgdown_DownloadDataCompleted;
                }
            }
        }
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:25,代码来源:SearchUrl.cs

示例2: Datadown_DownloadStringCompleted

        private static void Datadown_DownloadStringCompleted(object sender,
            System.Net.DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null || e.Result.Length <= 0 || e.Cancelled)
            {
                return;
            }
            var resultstr = e.Result;
            if (string.IsNullOrEmpty(resultstr)) return;

            // 得到<ul class=\"allsearch dashed boxPadd6\"> ~ </ul>
            var orignlis = resultstr.GetSingle("<table id=\"archiveResult\">", "</table>");
            orignlis = orignlis.Replace("<tbody>", "");
            if (string.IsNullOrEmpty(orignlis))
            {
                return;
            }
            // 得到 <li> ~ </li>
            var orignli = orignlis.GetValue("Detail", "Open");
            if (orignli == null || orignli.Count <= 0) return;

            // 解析数据
            var zuiReDatas = new System.Collections.Generic.List<LiuXingData>();
            foreach (var v in orignli)
            {
                var tag = SearchData.JieXiSearchData(v);
                if (tag != null)
                {
                    zuiReDatas.Add(tag);
                }
            }
            if (zuiReDatas.Count <= 0) return;

            // 遍历数据中的图片
            for (var i = 0; i < zuiReDatas.Count; i++)
            {
                var tag = zuiReDatas[i];
                if (tag != null)
                {
                    var imgtemp = tag.Img;
                    if (!string.IsNullOrEmpty(imgtemp))
                    {
                        using (
                            var imgdown = new System.Net.WebClient
                                {
                                    Encoding = System.Text.Encoding.UTF8,
                                    Proxy = PublicStatic.MyProxy
                                })
                        {
                            imgdown.DownloadDataAsync(new System.Uri(imgtemp), tag);
                            imgdown.DownloadDataCompleted += SearchImg.Imgdown_DownloadDataCompleted;
                        }
                    }
                }
            }
        }
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:56,代码来源:Search.cs

示例3: Get

 /// <summary>
 /// 使用 GET 方法异步获取某个特定 的 Uri 的资源,获取完成后无论成功还是失败,都将调用 HttpAsyncCompletedCallback 委托,并支持通过 HttpAsyncProgressCallback 报告下载进度。
 /// </summary>
 /// <param name="uri">要下载的资源。</param>
 /// <param name="completedCallback">完成下载后要执行的委托。</param>
 /// <param name="progressCallback">进度报告委托,可以为 null。</param>
 public static void Get(Uri uri, HttpAsyncCompletedCallback<byte[]> completedCallback, HttpAsyncProgressCallback progressCallback = null)
 {
     System.Net.WebClient client = new System.Net.WebClient();
     client.DownloadDataCompleted += (sender, e) => {
         completedCallback(e.Cancelled == false && e.Error == null && e.Result != null, e.Error, e.Result);
     };
     if (progressCallback != null) {
         client.DownloadProgressChanged += (sender, e) => {
             progressCallback(e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage);
         };
     }
     client.DownloadDataAsync(uri);
 }
开发者ID:ceeji,项目名称:CeejiCommonLibrary,代码行数:19,代码来源:HttpHelper.cs

示例4: StartImageDown

 /// <summary>
 /// 5.图片下载
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="imageurl"></param>
 /// <param name="iType"></param>
 public static void StartImageDown(LiuXingData tag, string imageurl, LiuXingType iType)
 {
     if (string.IsNullOrEmpty(imageurl)) return;
     using (
         var imgdown = new System.Net.WebClient
         {
             Encoding = iType.Encoding,
             Proxy = iType.Proxy
         })
     {
         if (!string.IsNullOrEmpty(imageurl))
         {
             var iClass = new LiuXingType
             {
                 Encoding = iType.Encoding,
                 Proxy = iType.Proxy,
                 Type = iType.Type,
                 Data = tag
             };
             var image = FileCachoHelper.ImageCacho(imageurl);
             if (image != null)
             {
                 iClass.Img = image;
                 GoToDisPlay(iClass);
             }
             else
             {
                 try
                 {
                     var imguri = new System.Uri(imageurl);
                     imgdown.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1581.2 Safari/537.36");
                     imgdown.DownloadDataAsync(imguri, iClass);
                     imgdown.DownloadDataCompleted += Imgdown_DownloadDataCompleted;
                 }
                 // ReSharper disable EmptyGeneralCatchClause
                 catch
                 // ReSharper restore EmptyGeneralCatchClause
                 {
                     // System.Windows.Forms.MessageBox.Show(exception.Message+zuiReDatas[i].Name+zuiReDatas[i].Img+i);
                 }
             }
         }
     }
 }
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:50,代码来源:ListStart.cs

示例5: CheckVersionAsync

        private void CheckVersionAsync()
        {
            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();

                System.Threading.AutoResetEvent waiter = new System.Threading.AutoResetEvent(false);
                wc.DownloadDataCompleted += new System.Net.DownloadDataCompletedEventHandler(DownloadDataCompletedCallback);

                System.Uri uri = new System.Uri(urlVersionFile);

                wc.DownloadDataAsync(uri, waiter);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:nusus,项目名称:behaviac,代码行数:18,代码来源:BehaviorTreeList.cs

示例6: Update

        ProtocolUpdateStatus Update(bool protocols)
        {
            lock (m_sync)
            {
                string backupPath = Path.Combine(GXCommon.ProtocolAddInsPath, "backup");
                if (!System.IO.Directory.Exists(backupPath))
                {
                    System.IO.Directory.CreateDirectory(backupPath);
                    Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(backupPath);
                }
                DataContractSerializer x = new DataContractSerializer(typeof(GXAddInList));
                GXAddInList localAddins;
                string path = Path.Combine(GXCommon.ProtocolAddInsPath, "updates.xml");
                ProtocolUpdateStatus status = ProtocolUpdateStatus.None;
                if (!System.IO.File.Exists(path))
                {
                    return status;
                }
                using (FileStream reader = new FileStream(path, FileMode.Open))
                {
                    localAddins = (GXAddInList)x.ReadObject(reader);
                }
                System.Net.WebClient client = new System.Net.WebClient();
                client.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadDataCompleted += new System.Net.DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
                foreach (GXAddIn it in localAddins)
                {
                    if ((protocols && it.Type != GXAddInType.AddIn) ||
                            (!protocols && it.Type != GXAddInType.Application))
                    {
                        continue;
                    }
                    if (it.State == AddInStates.Download || it.State == AddInStates.Update)
                    {
                        string AddInPath = Path.Combine(GXCommon.ProtocolAddInsPath, it.File);
                        if (it.Type == GXAddInType.AddIn ||
                                it.Type == GXAddInType.None)
                        {
                            AddInPath = GXCommon.ProtocolAddInsPath;
                        }
                        else if (it.Type == GXAddInType.Application)
                        {
                            AddInPath = Path.GetDirectoryName(typeof(GXUpdateChecker).Assembly.Location);
                        }
                        else
                        {
                            throw new Exception(Resources.UnknownType + it.Type.ToString());
                        }
                        try
                        {
                            string ext = Path.GetExtension(it.File);
                            if (string.Compare(ext, ".zip", true) == 0 ||
                                    string.Compare(ext, ".msi", true) == 0)
                            {
                                Target = it;
                                string tmpPath = Path.Combine(System.IO.Path.GetTempPath(), it.File);
                                Downloaded.Reset();
                                if (string.Compare(ext, ".zip", true) == 0)
                                {
                                    client.DownloadDataAsync(new Uri("http://www.gurux.org/updates/" + it.File), tmpPath);
                                }
                                else //If .msi
                                {
                                    client.DownloadDataAsync(new Uri("http://www.gurux.org/Downloads/" + it.File), tmpPath);
                                }

                                while (!Downloaded.WaitOne(100))
                                {
                                    Application.DoEvents();
                                }
                                if (string.Compare(ext, ".zip", true) == 0)
                                {
                                    throw new ArgumentException("Zip is not supported");
                                }
                                else //If .msi
                                {
                                    Process msi = new Process();
                                    msi.StartInfo.FileName = "msiexec.exe";
                                    msi.StartInfo.Arguments = "/i \"" + tmpPath + "\" /qr";
                                    msi.Start();
                                }
                            }
                            else
                            {
                                AddInPath = Path.Combine(AddInPath, it.File);
                                System.IO.File.WriteAllBytes(AddInPath, client.DownloadData("http://www.gurux.org/updates/" + it.File));
                                Gurux.Common.GXFileSystemSecurity.UpdateFileSecurity(AddInPath);
                                System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFile(AddInPath);
                                System.Diagnostics.FileVersionInfo newVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(asm.Location);
                                it.Version = it.InstalledVersion = newVersion.FileVersion;
                            }
                        }
                        //If file is in use.
                        catch (System.IO.IOException)
                        {
                            string cachedPath = Path.Combine(GXCommon.ProtocolAddInsPath, "cached");
                            if (!Directory.Exists(cachedPath))
                            {
                                Directory.CreateDirectory(cachedPath);
                                Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(cachedPath);
//.........这里部分代码省略.........
开发者ID:Gurux,项目名称:Gurux.Common,代码行数:101,代码来源:GXUpdateChecker.cs

示例7: JieXiOne

        /// <summary>
        /// 4.一级数据解析
        /// </summary>
        /// <param name="resultstr"></param>
        /// <param name="iType"></param>
        private static void JieXiOne(string resultstr, LiuXingType iType)
        {
            var zuiReDatas = new System.Collections.Generic.List<LiuXingData>();
            switch (iType.Type)
            {
                // 迅播影院正常列表
                case LiuXingEnum.XunboListItem:
                case LiuXingEnum.XunboSearchItem:
                    {
                        #region case LiuXingEnum.XunboListItem:

                        // 得到 <ul class=\"piclist\"> ~ </ul>
                        var orignlis = StringRegexHelper.GetSingle(resultstr, "<ul class=\"piclist\">", "</ul>");
                        if (string.IsNullOrEmpty(orignlis))
                        {
                            return;
                        }
                        // 得到 <li> ~ </li>
                        var orignli = StringRegexHelper.GetValue(orignlis, "<li>", "</li>");
                        if (orignli == null || orignli.Count <= 0) return;
                        for (var i = 0; i < orignli.Count; i++)
                        {
                            var celllistr = orignli[i];
                            if (string.IsNullOrEmpty(celllistr)) continue;
                            var tempcell = DataTagHelper.AnalyzeData(celllistr, iType);
                            if (tempcell != null)
                            {
                                zuiReDatas.Add(tempcell);
                            }
                        }
                        // 开始下载图片
                        StartImageDown(zuiReDatas, iType);
                        return;
                        #endregion
                    }
                // 人人影视正常列表
                case LiuXingEnum.YYetListItem:
                    {
                        #region case LiuXingEnum.YYetListItem:

                        // 得到<ul class="boxPadd dashed"> ~ </ul>
                        var orignlis = StringRegexHelper.GetSingle(resultstr, "<ul class=\"boxPadd dashed\">", "</ul>");
                        if (string.IsNullOrEmpty(orignlis))
                        {
                            return;
                        }
                        // 得到 <li> ~ </li>
                        var orignli = StringRegexHelper.GetValue(orignlis, "<li ", "</li>");
                        if (orignli == null || orignli.Count <= 0)
                        {
                            return;
                        }
                        for (var i = 0; i < orignli.Count; i++)
                        {
                            var celllistr = orignli[i];
                            if (!string.IsNullOrEmpty(celllistr))
                            {
                                var tag = DataTagHelper.AnalyzeData(celllistr, iType);
                                if (tag != null)
                                {
                                    zuiReDatas.Add(tag);
                                }
                            }
                        }
                        // 开始下载图片
                        StartImageDown(zuiReDatas, iType);
                        return;
                        #endregion
                    }
                case LiuXingEnum.YYetSearchItem:
                    {
                        #region case LiuXingEnum.YYetSearchItem:
                        if (!string.IsNullOrEmpty(iType.Sign) && iType.Sign.Contains("YYetSearchSecond"))
                        {
                            // 解析影视资料页的数据并生成模型
                            var tag = DataTagHelper.AnalyzeData(resultstr, iType);
                            if (tag == null) return;
                            if (!string.IsNullOrEmpty(tag.Img))
                            {
                                using (
                                    var imgdown = new System.Net.WebClient
                                    {
                                        Encoding = iType.Encoding,
                                        Proxy = iType.Proxy
                                    })
                                {
                                    iType.Data = tag;
                                    imgdown.DownloadDataAsync(new System.Uri(tag.Img), iType);
                                    imgdown.DownloadDataCompleted += Imgdown_DownloadDataCompleted;
                                }
                            }
                        }
                        else
                        {
                            // 得到<ul class=\"allsearch dashed boxPadd6\"> ~ </ul>
//.........这里部分代码省略.........
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:101,代码来源:ListStart.cs

示例8: CheckUpdateStatus

        public static void CheckUpdateStatus(string url,string xmlFileName,string zipFileName)
        {
            Ezhu.AutoUpdater.Lib.Constants.RemoteUrl = url;
            Ezhu.AutoUpdater.Lib.Constants.XmlFileName = xmlFileName;
            Ezhu.AutoUpdater.Lib.Constants.ZipFileName = zipFileName;
            System.Threading.ThreadPool.QueueUserWorkItem((s) =>
            {
                var client = new System.Net.WebClient();
                client.DownloadDataCompleted += (x, y) =>
                {
                    try
                    {
                        MemoryStream stream = new MemoryStream(y.Result);

                        XDocument xDoc = XDocument.Load(stream);
                        UpdateInfo updateInfo = new UpdateInfo();
                        XElement root = xDoc.Element("UpdateInfo");
                        updateInfo.AppName = root.Element("AppName").Value;
                        updateInfo.AppVersion = root.Element("AppVersion").Value;
                        updateInfo.RequiredMinVersion = root.Element("RequiredMinVersion").Value;
                        updateInfo.Desc = root.Element("Desc").Value;
                        updateInfo.MD5 = Guid.NewGuid().ToString();
                        updateInfo.UrlZip = Ezhu.AutoUpdater.Lib.Constants.RemoteUrl + Ezhu.AutoUpdater.Lib.Constants.ZipFileName;

                        stream.Close();
                        Updater.Instance.StartUpdate(updateInfo);
                    }
                    catch
                    { }
                };
                client.DownloadDataAsync(new Uri(Ezhu.AutoUpdater.Lib.Constants.RemoteUrl + Ezhu.AutoUpdater.Lib.Constants.XmlFileName));

            });
        }
开发者ID:zecak,项目名称:CarryBag,代码行数:34,代码来源:Updater.cs

示例9: DownloadUpdateInfoInternal

        /// <summary>
        /// 下载更新信息
        /// </summary>
        void DownloadUpdateInfoInternal(object sender, RunworkEventArgs e)
        {
            if (!IsUpdateInfoDownloaded)
            {
                var client = new System.Net.WebClient();
                client.DownloadProgressChanged += (x, y) =>
                {
                    e.ReportProgress((int)y.TotalBytesToReceive, (int)y.BytesReceived);
                };

                //下载更新信息
                e.PostEvent(OnDownloadUpdateInfo);

                //下载信息时不直接下载到文件中.这样不会导致始终创建文件夹
                var finished = false;
                Exception ex = null;
                client.DownloadDataCompleted += (x, y) =>
                {
                    ex = y.Error;
                    if (ex == null) UpdateContent = System.Text.Encoding.UTF8.GetString(y.Result);
                    finished = true;
                };
                client.DownloadDataAsync(new Uri(UpdateUrl));
                while (!finished)
                {
                    System.Threading.Thread.Sleep(50);
                }
                if (this.Exception != null) throw ex;
                e.PostEvent(OnDownloadUpdateInfoFinished);

                //是否返回了正确的结果?
                if (string.IsNullOrEmpty(UpdateContent))
                {
                    throw new ApplicationException("服务器返回了不正确的更新结果");
                }
            }
            if (UpdateInfo == null)
            {
                if (string.IsNullOrEmpty(UpdateContent))
                {
                    UpdateContent = System.IO.File.ReadAllText(UpdateInfoFilePath, System.Text.Encoding.UTF8);
                }

                UpdateInfo = XMLSerializeHelper.XmlDeserializeFromString<UpdateInfo>(UpdateContent);
            }
        }
开发者ID:eopeter,项目名称:dmelibrary,代码行数:49,代码来源:Updater.cs

示例10: DownloadUpdateFile

        public void DownloadUpdateFile(string urlzip)
        {
            string url = urlzip;
            var client = new System.Net.WebClient();
            client.DownloadProgressChanged += (sender, e) =>
            {
                UpdateProcess(e.BytesReceived, e.TotalBytesToReceive);
            };
            client.DownloadDataCompleted += (sender, e) =>
            {
                string zipFilePath = System.IO.Path.Combine(updateFileDir, "update.zip");
                byte[] data = e.Result;
                BinaryWriter writer = new BinaryWriter(new FileStream(zipFilePath, FileMode.OpenOrCreate));
                writer.Write(data);
                writer.Flush();
                writer.Close();

                System.Threading.ThreadPool.QueueUserWorkItem((s) =>
                {
                    Action f = () =>
                    {
                       txtProcess.Text = "开始更新程序...";
                    };
                    this.Dispatcher.Invoke(f);

                    string tempDir = System.IO.Path.Combine(updateFileDir, "temp");
                    if (!Directory.Exists(tempDir))
                    {
                        Directory.CreateDirectory(tempDir);
                    }
                    UnZipFile(zipFilePath, tempDir);

                    //移动文件
                    //App
                    if(Directory.Exists(System.IO.Path.Combine(tempDir)))
                    {
                        CopyDirectory(System.IO.Path.Combine(tempDir),appDir);
                    }

                    f = () =>
                    {
                        txtProcess.Text = "更新完成!";

                        try
                        {
                            //清空缓存文件夹
                            string rootUpdateDir = updateFileDir.Substring(0, updateFileDir.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
                            System.IO.Directory.Delete(rootUpdateDir, true);
                        }
                        catch (Exception ex)
                        {
                        }

                    };
                    this.Dispatcher.Invoke(f);

                    try
                    {
                        f = () =>
                        {
                            AlertWin alert = new AlertWin("更新完成,是否现在启动软件?") { WindowStartupLocation = WindowStartupLocation.CenterOwner, Owner = this };
                            alert.Title = "更新完成";
                            alert.Loaded += (ss, ee) =>
                            {
                                alert.YesButton.Width = 40;
                                alert.NoButton.Width = 40;
                            };
                            alert.Width=300;
                            alert.Height = 200;
                            alert.ShowDialog();
                            if (alert.YesBtnSelected)
                            {
                                //启动软件
                                string exePath = System.IO.Path.Combine(appDir, callExeName + ".exe");
                                System.IO.File.AppendAllText("d:\\1.txt", "启动软件(exePath):" + exePath);
                                var info = new System.Diagnostics.ProcessStartInfo(exePath);
                                info.UseShellExecute = true;
                                info.WorkingDirectory = appDir;// exePath.Substring(0, exePath.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
                                System.Diagnostics.Process.Start(info);
                            }
                            else
                            {

                            }
                            this.Close();
                        };
                        this.Dispatcher.Invoke(f);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                    }
                });

            };
            client.DownloadDataAsync(new Uri(url));
        }
开发者ID:zecak,项目名称:CarryBag,代码行数:97,代码来源:DownFileProcess.xaml.cs


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