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


C# WebClient.CancelAsync方法代码示例

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


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

示例1: OnTestButtonClicked

 protected void OnTestButtonClicked(object sender, EventArgs e)
 {
     testButton.State = Gtk.StateType.Insensitive;
     speedStatus.Text = "Testing... ";
     WebClient japan = new WebClient ();
     japan.Proxy = new WebProxy ("127.0.0.1:13370");
     japan.DownloadDataAsync (new Uri ("http://ipv4.download.thinkbroadband.com:8080/5MB.zip"));
     Stopwatch tmr = new Stopwatch ();
     tmr.Start ();
     double jSpeed;
     japan.DownloadDataCompleted += delegate(object sdr, DownloadDataCompletedEventArgs E) {
         if (true) {
             speedStatus.Text = "";
             jSpeed = (5000000 / 1024.0) / (tmr.ElapsedMilliseconds / 1000);
             GLib.Timeout.Add (200, updateStatus);
             theSpeed = jSpeed.ToString ().Substring (0, 6);
             theSpeed = "Result: " + Math.Round (jSpeed).ToString () + " KiB/s";
             tmr.Reset ();
             tmr.Stop ();
             japan.CancelAsync ();
             japan.CancelAsync ();
             japan.CancelAsync ();
             testButton.Sensitive = true;
         }
     };
 }
开发者ID:quantum1423-dustbin,项目名称:Kirisurf-obsolete-obsolete,代码行数:26,代码来源:MainWindow.cs

示例2: Execute


//.........这里部分代码省略.........
        form.AddField ("v", theVersion);

        if (!string.IsNullOrEmpty (thePackaging)) {
            form.AddField ("p", thePackaging);
        }

        if (!string.IsNullOrEmpty (theClassifier)) {
            form.AddField ("c", theClassifier);
        }

        if (!string.IsNullOrEmpty (theExtension)) {
            form.AddField ("e", theExtension);
        }

        var bytes = File.ReadAllBytes (theInputFileName);
        form.AddBinaryData ("file", bytes, new FileInfo (theInputFileName).Name);

        var hash = UTils.ComputeHash (bytes);
        if (UTPreferences.DebugMode) {
            Debug.Log ("SHA1-Hash of file to upload: " + hash);
        }

        string authString = theUserName + ":" + thePassword;
        var authBytes = System.Text.UTF8Encoding.UTF8.GetBytes (authString);

        var headers = new Hashtable ();
        foreach (var key in form.headers.Keys) {
            headers.Add (key, form.headers [key]);
        }

        headers.Add ("Authorization", "Basic " + System.Convert.ToBase64String (authBytes));
        var url = UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/content");
        using (var www = new WWW (url, form.data, headers)) {
            do {
                yield return "";
            } while(!www.isDone && !context.CancelRequested);

            if (UTPreferences.DebugMode) {
                Debug.Log ("Server Response: " + www.text);
            }
        }

        if (!context.CancelRequested) {

            using (var wc = new WebClient()) {

                if (!string.IsNullOrEmpty (theUserName)) {
                    Debug.Log("Setting credentials" );
                    wc.Credentials = new NetworkCredential (theUserName, thePassword);
                }

                Uri uri = new Uri (UTils.BuildUrl (theNexusUrl, "/service/local/artifact/maven/resolve?") +
            "g=" + Uri.EscapeUriString (theGroupId) +
            "&a=" + Uri.EscapeUriString (theArtifactId) +
            "&v=" + Uri.EscapeUriString (theVersion) +
            "&r=" + Uri.EscapeUriString (theRepoId) +
            "&p=" + Uri.EscapeUriString (thePackaging) +
            (!string.IsNullOrEmpty (theClassifier) ? "&c=" + Uri.EscapeUriString (theClassifier) : "") +
            (!string.IsNullOrEmpty (theExtension) ? "&e=" + Uri.EscapeUriString (theExtension) : ""));

                var downloadFinished = false;
                var error = false;
                string result = null;
                wc.DownloadStringCompleted += delegate( object sender, DownloadStringCompletedEventArgs e) {
                    downloadFinished = true;
                    error = e.Error != null;
                    if (error) {
                        Debug.LogError ("An error occured while downloading artifact information. " + e.Error.Message, this);
                    } else {
                        result = (string)e.Result;
                    }
                };

                wc.DownloadStringAsync (uri);

                do {
                    yield return "";
                    if (context.CancelRequested) {
                        wc.CancelAsync ();
                    }
                } while(!downloadFinished);

                if (!context.CancelRequested) {

                    if (!error) {
                        if (UTPreferences.DebugMode) {
                            Debug.Log ("Server Response: " + result);
                        }
                        if (result.Contains ("<sha1>" + hash + "</sha1>")) {
                            Debug.Log ("Successfully uploaded artifact " + theInputFileName + ".", this);
                        } else {
                            throw new UTFailBuildException ("Upload failed. Checksums do not match.", this);
                        }
                    } else {
                        throw new UTFailBuildException ("Artifact verification failed", this);
                    }
                }
            }
        }
    }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:101,代码来源:UTUploadDependencyAction.cs

示例3: Execute

    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
            EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed) {
            Debug.LogWarning("You have currently set the build target to 'Web Player'. This may cause interference with actions that access the internet. If you get an error message about cross domain policy from this action, switch the target to 'PC and Mac Standalone' and try again.");
        }

        var theNexusUrl = nexusUrl.EvaluateIn (context);
        if (string.IsNullOrEmpty (theNexusUrl)) {
            throw new UTFailBuildException ("You need to specify the nexus URL", this);
        }

        var theRepoId = repositoryId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theRepoId)) {
            throw new UTFailBuildException ("You need to specify the repository id.", this);
        }

        var theUserName = userName.EvaluateIn (context);
        var thePassword = password.EvaluateIn (context);

        var theGroupId = groupId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theGroupId)) {
            throw new UTFailBuildException ("You need to specify the group id.", this);
        }

        var theArtifactId = artifactId.EvaluateIn (context);
        if (string.IsNullOrEmpty (theArtifactId)) {
            throw new UTFailBuildException ("You need to specify the artifact id.", this);
        }

        var theVersion = version.EvaluateIn (context);
        if (string.IsNullOrEmpty (theVersion)) {
            throw new UTFailBuildException ("You need to specify the version.", this);
        }

        var thePackaging = packaging.EvaluateIn(context);
        if (string.IsNullOrEmpty (thePackaging)) {
            throw new UTFailBuildException ("You need to specify the packaging.", this);
        }

        var theExtension = extension.EvaluateIn(context);
        var theClassifier = classifier.EvaluateIn(context);

        var theOutputFileName = outputFileName.EvaluateIn (context);
        if (string.IsNullOrEmpty (theOutputFileName)) {
            throw new UTFailBuildException ("You need to specify the output file name.", this);
        }

        if (Directory.Exists (theOutputFileName)) {
            throw new UTFailBuildException ("The specified output file " + theOutputFileName + " is a directory.", this);
        }

        UTFileUtils.EnsureParentFolderExists (theOutputFileName);

        // TODO: ignore SSL certs if required
        using (var wc = new WebClient()) {

            if (!string.IsNullOrEmpty (theUserName)) {
                wc.Credentials = new NetworkCredential (theUserName, thePassword);
            }

            Uri uri = new Uri (theNexusUrl + "/service/local/artifact/maven/content?" +
            "g=" + Uri.EscapeUriString (theGroupId) +
            "&a=" + Uri.EscapeUriString (theArtifactId) +
            "&v=" + Uri.EscapeUriString (theVersion) +
            "&r=" + Uri.EscapeUriString (theRepoId) +
            "&p=" + Uri.EscapeUriString(thePackaging) +
            (!string.IsNullOrEmpty(theClassifier) ? "&c=" + Uri.EscapeUriString(theClassifier) : "") +
            (!string.IsNullOrEmpty(theExtension) ? "&e=" + Uri.EscapeUriString(theExtension) : ""));

            downloadFinished = false;
            error = false;
            wc.DownloadFileCompleted += delegate( object sender, AsyncCompletedEventArgs e) {
                downloadFinished = true;
                error = e.Error != null;
                if (error) {
                    Debug.LogError ("An error occured while downloading. " + e.Error.Message, this);
                }
            };

            wc.DownloadFileAsync (uri, theOutputFileName);

            do {
                yield return "";
                if (context.CancelRequested) {
                    wc.CancelAsync ();
                }
            } while(!downloadFinished);

            if (!error && !context.CancelRequested) {
                Debug.Log ("Successfully downloaded artifact to " + theOutputFileName + ".", this);
            }

            if (context.CancelRequested) {
                File.Delete(theOutputFileName);
            }

        }
    }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:99,代码来源:UTDownloadDependencyAction.cs


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