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


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

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


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

示例1: Api

        public static string Api(string Temperature,string Humidity)
        {
            string url = (string)Properties.Settings.Default["ApiAddress"];
            string resText = "";
            try {
                System.Net.WebClient wc = new System.Net.WebClient();
                System.Collections.Specialized.NameValueCollection ps =
                    new System.Collections.Specialized.NameValueCollection();

                ps.Add("MachineName", (string)Properties.Settings.Default["MachineName"]);
                ps.Add("Temperature", Temperature);
                ps.Add("Humidity", Humidity);

                byte[] ResData = wc.UploadValues(url, ps);
                wc.Dispose();
                resText = System.Text.Encoding.UTF8.GetString(ResData);
                if (resText != "OK")
                {
                    return "APIエラー";
                }
            }
            catch (Exception ex){
                return ex.ToString();
            }

            return null;
        }
开发者ID:ichirowo,项目名称:Room-temperature_IoT,代码行数:27,代码来源:WebAccess.cs

示例2: APIRequest

 private static string APIRequest(string request)
 {
     System.Net.WebClient http = new System.Net.WebClient();
     http.Headers.Add("X-Mashape-Key: LigI9kHL7omsh5NN0rCWg0d6PA5jp1TdGUUjsnexk2zQ42JwCA");
     var response = http.DownloadString(request);
     http.Dispose();
     return response;
 }
开发者ID:Folkstorm,项目名称:My-Heartstone-cards,代码行数:8,代码来源:MainWindow.xaml.cs

示例3: PopulateScoreAndBody

		public void PopulateScoreAndBody()
		{
			var wb = new System.Net.WebClient();
			var html = wb.DownloadString(URL);

			Body = GetBody(html);
			Score = GetScore(html);

			wb.Dispose();
		}
开发者ID:ProgramFOX,项目名称:Phamhilator,代码行数:10,代码来源:Post.cs

示例4: DownLoad

        /// <summary>
        /// 开始下载更新升级包
        /// </summary>
        public void DownLoad()
        {
            System.Net.WebClient webC = new System.Net.WebClient();//用于读取文件最新版信息的WebClient
            string versionStr = "";

            try
            {
                versionStr = webC.DownloadString(this.VersionFileURI);
            }
            catch { }

            if (versionStr.Trim() == "")//如果没有获得升级文件版本信息
            {
                webC.Dispose();
                this.webFile1.Dispose();
                this.Dispose();
            }
            else
            {
                webC.Dispose();
                if (versionStr.Trim() != System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())//如果软件版本与现有的客户端不同,则下载最新版本
                    if (MessageBox.Show(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
                        + "已有更新版本,是否下载并安装?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        this.Visible = true;
                        this.Width = 334;
                        this.Height = 154;
                        this.label1.Text = "正在下载更新程序,请稍等...";
                        this.timer1.Enabled = true;//开始执行下载最新版升级程序任务
                    }
                    else
                    {
                        this.webFile1.Dispose();
                        this.Dispose();
                    }
                else
                {
                    this.webFile1.Dispose();
                    this.Dispose();
                }
            }
        }
开发者ID:cheehwasun,项目名称:ourmsg,代码行数:45,代码来源:webUpdate.cs

示例5: Main

        static void Main(string[] args)
        {
            DBUtil.Connect();

            Logger.Instance.Debug("aa");

            // YPからチャンネル情報を取得
            List<ChannelDetail> channelDetails = GetChannelDetails();

            // 配信者マスターの更新
            UpdateChannel(channelDetails);

            // スレッド情報の更新
            UpdateBBSThread(channelDetails);

            // レス情報の更新
            UpdateBBSResponse();

            /*
            List<string> imgList = new List<string>();
            // レス一覧の取得
            List<BBSResponse> resList = BBSResponseDao.Select();
            foreach (BBSResponse res in resList)
            {
                Match match = Regex.Match(res.Message, @"ttp://.*\.(jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)");

                if (match.Success)
                {
                    string imageUrl = "h" + match.Value;
                    imgList.Add(imageUrl);
                    ImageLinkDao.Insert(res.ThreadUrl, res.ResNo, imageUrl, res.WriteTime);
                }
            }
             */

            List<ImageLink> imageList = ImageLinkDao.Select();

            foreach (ImageLink link in imageList)
            {
                try
                {
                    System.Net.WebClient wc = new System.Net.WebClient();
                    wc.DownloadFile(link.ImageUrl, @"S:\MyDocument_201503\dev\github\PecaTsu_BBS\src_BBS\img\" + (link.WriteTime.Replace("/", "").Replace(":", "")) + ".jpg");
                    wc.Dispose();
                }
                catch (Exception)
                {
                }
            }

            DBUtil.Close();
        }
开发者ID:shule517,项目名称:PecaTsu,代码行数:52,代码来源:Program.cs

示例6: downloadFile

 public static void downloadFile(string url, string sourcefile, string user, string pwd)
 {
     try
     {
         System.Net.WebClient Client = new System.Net.WebClient();
         Client.Credentials = new System.Net.NetworkCredential(user, pwd);
         Client.DownloadFile(url, sourcefile);
         Client.Dispose();
     }
     catch (Exception e)
     {
         throw (e);
     }
 }
开发者ID:wpaven,项目名称:malone,代码行数:14,代码来源:UserControl1.cs

示例7: GetWebServiceAssembly

        /// <summary>  
        /// 根据WEBSERVICE地址获取一个 Assembly  
        /// </summary>  
        /// <param name="p_Url">地址</param>  
        /// <param name="p_NameSpace">命名空间</param>  
        /// <returns>返回Assembly</returns>  
        public static Assembly GetWebServiceAssembly(string p_Url, string p_NameSpace)
        {
            try
            {
                System.Net.WebClient _WebClient = new System.Net.WebClient();

                System.IO.Stream _WebStream = _WebClient.OpenRead(p_Url);

                ServiceDescription _ServiceDescription = ServiceDescription.Read(_WebStream);

                _WebStream.Close();
                _WebClient.Dispose();
                ServiceDescriptionImporter _ServiceDescroptImporter = new ServiceDescriptionImporter();
                _ServiceDescroptImporter.AddServiceDescription(_ServiceDescription, "", "");
                System.CodeDom.CodeNamespace _CodeNameSpace = new System.CodeDom.CodeNamespace(p_NameSpace);
                System.CodeDom.CodeCompileUnit _CodeCompileUnit = new System.CodeDom.CodeCompileUnit();
                _CodeCompileUnit.Namespaces.Add(_CodeNameSpace);
                _ServiceDescroptImporter.Import(_CodeNameSpace, _CodeCompileUnit);

                System.CodeDom.Compiler.CodeDomProvider _CodeDom = new Microsoft.CSharp.CSharpCodeProvider();
                System.CodeDom.Compiler.CompilerParameters _CodeParameters = new System.CodeDom.Compiler.CompilerParameters();
                _CodeParameters.GenerateExecutable = false;
                _CodeParameters.GenerateInMemory = true;
                _CodeParameters.ReferencedAssemblies.Add("System.dll");
                _CodeParameters.ReferencedAssemblies.Add("System.XML.dll");
                _CodeParameters.ReferencedAssemblies.Add("System.Web.Services.dll");
                _CodeParameters.ReferencedAssemblies.Add("System.Data.dll");

                System.CodeDom.Compiler.CompilerResults _CompilerResults = _CodeDom.CompileAssemblyFromDom(_CodeParameters, _CodeCompileUnit);

                if (_CompilerResults.Errors.HasErrors)
                {
                    string _ErrorText = "";
                    foreach (CompilerError _Error in _CompilerResults.Errors)
                    {
                        _ErrorText += _Error.ErrorText + "/r/n";
                    }
                    throw new Exception(_ErrorText);
                }

                return _CompilerResults.CompiledAssembly;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:53,代码来源:Class1.cs

示例8: Main

        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage :  ");
                Console.WriteLine("cssd http://example.com/styles.css");
                return;
            }
            // No options. Just URL of the css.
            string cssFile = args[0];

            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                Uri furi = new Uri(cssFile);
                string content = wc.DownloadString(furi);
                Console.WriteLine("File downloaded.. Looking for url() references to download.");
                DirectoryInfo di = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, furi.Segments[furi.Segments.Length - 1]));
                UriBuilder ub = new UriBuilder();
                ub.Host = furi.Host;
                ub.Scheme = furi.Scheme;
                System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex("url(\\((.*?)\\))");
                MatchCollection matches = rg.Matches(content);
                int i = 0;
                foreach (Match item in matches)
                {
                    string url = item.Groups[2].Value;
                    ub.Path = url;
                    wc.DownloadFile(ub.Uri, System.IO.Path.Combine(di.FullName, ub.Uri.Segments[ub.Uri.Segments.Length - 1]));
                    content = content.Replace(url, ub.Uri.Segments[ub.Uri.Segments.Length - 1]);
                    DrawProgressBar(i, matches.Count, 40, '=');
                    i++;
                }
                wc.Dispose();

                DrawProgressBar(matches.Count, matches.Count, 40, '=');
                Console.WriteLine("");
                Console.WriteLine("Complete!");
                System.Threading.Thread.Sleep(300);
                System.IO.File.WriteAllText(System.IO.Path.Combine(di.FullName, furi.Segments[furi.Segments.Length - 1]), content);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }
        }
开发者ID:buraksarica,项目名称:CssDownloader,代码行数:46,代码来源:Program.cs

示例9: Run

        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            string apiIds = ApiId;
            if (string.IsNullOrEmpty(ApiId))
            {
                apiIds = Rawler.Tool.GlobalVar.GetVar("YahooApiId");
            }
            if (string.IsNullOrEmpty(apiIds))
            {
                Rawler.Tool.ReportManage.ErrReport(this, "YahooApiIdがありません。SetTmpValで指定してください");
                return;
            }
            string apiId = apiIds.Split(',').OrderBy(n => Guid.NewGuid()).First();
            string baseUrl = "http://jlp.yahooapis.jp/KeyphraseService/V1/extract";
            var post = "appid=" + apiId + "&sentence=" +Uri.EscapeUriString(GetText());
            string result = string.Empty;
            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                wc.Headers.Add("Content-Type","application/x-www-form-urlencoded");
                wc.Encoding = Encoding.UTF8;
                result = wc.UploadString(new Uri(baseUrl), "POST", post);
                wc.Dispose();
            }
            catch(Exception e)
            {
                ReportManage.ErrReport(this, e.Message +"\t"+GetText());
            }
            if (result != string.Empty)
            {
                var root = XElement.Parse(result);
                var ns = root.GetDefaultNamespace();
                var list = root.Descendants(ns + "Result").Select(n => new KeyphraseResult() { Keyphrase = n.Element(ns + "Keyphrase").Value, Score = double.Parse(n.Element(ns + "Score").Value) });

                List<string> list2 = new List<string>();
                foreach (var item in list)
                {
                    list2.Add(Codeplex.Data.DynamicJson.Serialize(item));
                }

                base.RunChildrenForArray(runChildren, list2);
            }
        }
开发者ID:kiichi54321,项目名称:Rawler,代码行数:47,代码来源:Keyphrase.cs

示例10: Discover

        private static void Discover()
        {
            var c = new System.Net.WebClient();
            var p = c.DownloadString("http://localhost:4743/PingTrace/Ping");
            var ts = c.DownloadString("http://localhost:4743/PingTrace/Traces");

            Console.WriteLine("Ping:");
            Console.WriteLine(p);
            Console.WriteLine();

            Console.WriteLine("Traces:");
            Console.WriteLine(ts);
            Console.WriteLine();

            var traces = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<Patware.PingTrace.Core.TraceDestination>>(ts);

            foreach (var traceDestination in traces)
            {
                Console.WriteLine();
                Console.WriteLine(traceDestination.Name);

                var s = c.DownloadString(string.Format("http://localhost:4743/PingTrace/Trace?destination={0}", traceDestination.Name));

                var traceResults = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<Patware.PingTrace.Core.TraceResult>>(s);

                foreach (var traceResult in traceResults)
                {
                    Console.Write("\t");
                    Console.WriteLine(traceResult.Name);
                    Console.WriteLine("\tExpected Time: (max/avg) ({0}/{1}, actual: {2})", traceDestination.ExpectedElapsedMilisecondsMax, traceDestination.ExpectedElapsedMilisecondsAverage, traceResult.Elapsed.TotalMilliseconds);
                    Console.WriteLine("\tExpected Identity: {0} actual: {1}", traceDestination.ExpectedIdentity, traceResult.Identity);
                    Console.WriteLine("\tExpected MachineName: {0} actual: {1}", string.Join(",", traceDestination.ExpectedMachineNames), traceResult.MachineName);

                    Console.WriteLine("\tPayload Description: {0}", traceDestination.PayloadDescription);
                    Console.WriteLine("\tPayload: {0}", traceResult.Payload);
                    Console.WriteLine();

                }
            }

            c.Dispose();
        }
开发者ID:patware,项目名称:PingTrace,代码行数:42,代码来源:Program.cs

示例11: init

        public void init()
        {
            System.Net.WebClient wc = new System.Net.WebClient();
            wc.DownloadFile(versionUrl, MOCraftSystem.gameDir + @"versions.json");
            wc.Dispose();

            StreamReader sr = new StreamReader(MOCraftSystem.gameDir + @"versions.json");
            JObject joj = JObject.Parse(sr.ReadToEnd());
            sr.Dispose();
            sr.Close();

            MOCraftSystem.latestSnapshot = joj["latest"]["snapshot"].ToString();
            MOCraftSystem.latestRelease = joj["latest"]["release"].ToString();
            foreach (JObject jojC1 in (JArray)joj["versions"]) {
                MOCraftSystem.versionId.Add(jojC1["id"].ToString());
                MOCraftSystem.versionType.Add(jojC1["type"].ToString());
            }

            return;
        }
开发者ID:MOCraftStudio,项目名称:MOCraftLauncher,代码行数:20,代码来源:VersionManager.cs

示例12: getDNSINFO

        public dynamic getDNSINFO()
        {
            string url = "https://www.cloudflare.com/api_json.html";

            System.Net.WebClient wc = new System.Net.WebClient();
            //NameValueCollectionの作成
            System.Collections.Specialized.NameValueCollection ps = new System.Collections.Specialized.NameValueCollection();
            //送信するデータ(フィールド名と値の組み合わせ)を追加
            ps.Add("a", "rec_load_all");
            ps.Add("tkn", KEY);
            ps.Add("email", EMAIL);
            ps.Add("z", DOMAIN);
            //データを送信し、また受信する
            byte[] resData = wc.UploadValues(url, ps);
            wc.Dispose();

            //受信したデータを表示する
            string resText = System.Text.Encoding.UTF8.GetString(resData);

            var model = new JavaScriptSerializer().Deserialize<dynamic>(resText);

            for (int i = 0; i < model["response"]["recs"]["count"]; i++)
            {
                string type = model["response"]["recs"]["objs"][i]["type"];

                if (type == "A")
                {
                    return new
                    {
                        rec_id = model["response"]["recs"]["objs"][i]["rec_id"],
                        content = model["response"]["recs"]["objs"][i]["content"],
                        name = model["response"]["recs"]["objs"][i]["name"],
                        service_mode = model["response"]["recs"]["objs"][i]["service_mode"],
                        ttl = model["response"]["recs"]["objs"][i]["ttl"]
                    };
                }

            }

            return null;
        }
开发者ID:SlaynationCoder,项目名称:CloudFlare-DNS-Updator,代码行数:41,代码来源:CFAPI.cs

示例13: SendToArduino

 public static String SendToArduino(String url)
 {
     System.Diagnostics.Debug.WriteLine( String.Format("SendToArduino: url={0}", url) );
     System.Net.WebClient ArduinoWebClient = null;
     try
     {
         ArduinoWebClient = new System.Net.WebClient();
         var content = ArduinoWebClient.DownloadString(url);
         return content;
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(String.Format("SendToArduino: error={0}", e));
         return "error"+e;
     }
     finally
     {
         if (ArduinoWebClient != null)
             ArduinoWebClient.Dispose();
     }
 }
开发者ID:eighthrazz,项目名称:luminaryT,代码行数:21,代码来源:ArduinoHelper.cs

示例14: RunMinecraft

 public void RunMinecraft()
 {
     if (!File.Exists(exePath))
     {
         if(!Directory.Exists(Directory.GetParent(exePath).FullName))
         {
             Directory.CreateDirectory(Directory.GetParent(exePath).FullName);
         }
         System.Net.WebClient wc = new System.Net.WebClient();
         wc.DownloadFile(@"https://s3.amazonaws.com/MinecraftDownload/launcher/Minecraft.exe", exePath);
         wc.Dispose();
     }
     string batPath = Environment.CurrentDirectory + @"\emb\run.bat";
     var customEnabled = Properties.Settings.Default.UseCustom && File.Exists(Environment.CurrentDirectory + @"\emb\custom.txt");
     File.WriteAllText(batPath, GenerateScript(customEnabled),Encoding.GetEncoding("Shift-JIS"));
     var p = new Process();
     p.StartInfo.FileName = batPath;
     if(!Properties.Settings.Default.LogEnabled)
     {
         p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     }
     p.Start();
 }
开发者ID:laco0416,项目名称:McLauncher2,代码行数:23,代码来源:RunManager.cs

示例15: uDefine

 public string uDefine(string term)
 {
     try
     {
         term = term.Replace(" ", "+");
         string uDictionaryURL = "http://www.urbandictionary.com/define.php?term=" + term;
         System.Net.WebClient webClient = new System.Net.WebClient();
         string webSource = webClient.DownloadString(uDictionaryURL);
         webClient.Dispose();
         webSource = webSource.Trim().Replace("\0", "").Replace("\n", "");
         string firstDelimiter = "<div class=\"definition\">";
         string[] firstSplit = webSource.Split(new string[] { firstDelimiter }, StringSplitOptions.None);
         string secondDelimiter = "</div>";
         string[] secondSplit = firstSplit[1].Split(new string[] { secondDelimiter }, StringSplitOptions.None);
         return System.Text.RegularExpressions.Regex.Replace(secondSplit[0], @"<[^>]*>", "");
     }
     catch (Exception ex)
     {
         return ex.ToString();
     }
 }
开发者ID:ArkaneCow,项目名称:Obsidian,代码行数:21,代码来源:Class1.cs


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