美文网首页
C#使用semaphore 管理异步下载请求的代码

C#使用semaphore 管理异步下载请求的代码

作者: laohuli | 来源:发表于2019-01-15 12:24 被阅读0次

把做工程过程中重要的内容做个珍藏,下面的代码是关于C#使用semaphore 管理异步下载请求的代码。

            foreach (var pin in new HashSet<string>(pinIdList))

            {

                semaphor.WaitOne();

                Console.Write(">");

                var pinClient = new WebClient();

                pinClient.DownloadStringCompleted += (sender, ex) =>

                {

                    var html = ex.Result.Replace("n", "");

                    pinClient.Dispose();

                    lock (pinIdList)

                    {

                    }

                    Console.Write("<");

                    semaphor.Release();

                };

            }

            semaphor.Dispose();

            Console.WriteLine();

相关文章

网友评论

      本文标题:C#使用semaphore 管理异步下载请求的代码

      本文链接:https://www.haomeiwen.com/subject/veaedqtx.html