当前位置:网站首页>C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
2022-07-03 12:52:00 【superfreak】
using System;
using System.Net;
using System.Diagnostics;
namespace Chapter20AsyncSample_WithoutUsingAsyncP394
{
class MyDownloadingString
{
Stopwatch sw=new Stopwatch();// class System.Diagnostic.Stopwatch: Provides a set of methods and properties
//that you can use to accurately measure elapsed time.
public void DoRun()
{
const int LargeNumber = 6000000;
sw.Start();
int t1 = CountCharacters(1,"http://www.baidu.com");
int t2 = CountCharacters(2, "http://www.csdn.net");
CountToALargeNumber(1,LargeNumber); CountToALargeNumber(2, LargeNumber);
CountToALargeNumber(3,LargeNumber); CountToALargeNumber(4, LargeNumber);
Console.WriteLine("Chars in http://www.baidu.com :{0}", t1);
Console.WriteLine("Chars in http://www.csdn.net :{0}", t2);
}
private int CountCharacters(int id,string uriString)
{
WebClient wc1 = new WebClient();// class System.Net.WebClient Provide a common method for obtaining information from resources ( use URI identification ) Send and receive data .
Console.WriteLine("Starting call {0}:{1,4:N0} ms",id,sw.Elapsed.TotalMilliseconds);
string result = wc1.DownloadString(new Uri(uriString));// Download the resource as a string . Returns a string
Console.WriteLine(" Call {0} completed:{1,4:N0} ms",id,sw.Elapsed.TotalMilliseconds);
//Console.WriteLine("{0}", result);
return result.Length;
}
private void CountToALargeNumber(int id,int value)
{
for (long i=0;i<value;i++)
;
Console.WriteLine(" End counting {0}:{1,4:N0} ms",id, sw.Elapsed.TotalMilliseconds);
}
}
class Program
{
static void Main(string[] args)
{
MyDownloadingString ds = new MyDownloadingString();
ds.DoRun();
Console.WriteLine("Hello World!");
}
}
}
边栏推荐
- Xctf mobile--app3 problem solving
- 【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
- Seven second order ladrc-pll structure design of active disturbance rejection controller
- Leetcode234 palindrome linked list
- The latest version of blind box mall thinkphp+uniapp
- How to convert a decimal number to binary in swift
- Exploration of sqoop1.4.4 native incremental import feature
- Public and private account sending prompt information (user microservice -- message microservice)
- Sword finger offer14 the easiest way to cut rope
- 【数据库原理复习题】
猜你喜欢

Analysis of a music player Login Protocol
![[problem exploration and solution of one or more filters or listeners failing to start]](/img/82/e7730d289c4c1c4800b520c58d975a.jpg)
[problem exploration and solution of one or more filters or listeners failing to start]

【数据挖掘复习题】

强大的头像制作神器微信小程序

Grid connection - Analysis of low voltage ride through and island coexistence

最新版抽奖盲盒运营版

How to get user location in wechat applet?

studio All flavors must now belong to a named flavor dimension. Learn more

Integer case study of packaging

T430 toss and install OS majave 10.14
随机推荐
alright alright alright
Deeply understand the mvcc mechanism of MySQL
[exercise 5] [Database Principle]
[comprehensive question] [Database Principle]
剑指Offer04. 二维数组中的查找【中等】
Idea packages the web project into a war package and deploys it to the server to run
[Exercice 5] [principe de la base de données]
Sword finger offer07 Rebuild binary tree
Kung Fu pays off, and learning is done
4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
Xctf mobile--app1 problem solving
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
Social community forum app ultra-high appearance UI interface
【综合题】【数据库原理】
【習題五】【數據庫原理】
【习题六】【数据库原理】
Xctf mobile--rememberother problem solving
Swift return type is a function of function
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number