当前位置:网站首页>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!");
}
}
}
边栏推荐
- Openstack node address change
- 【習題五】【數據庫原理】
- Tensorflow binary installation & Failure
- T430 toss and install OS majave 10.14
- 最新版抽奖盲盒运营版
- Sword finger offer04 Search in two-dimensional array [medium]
- Attack and defense world mobile--ph0en1x-100
- ORM use of node -serialize
- Sword finger offer10- I. Fibonacci sequence
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
猜你喜欢

2021 autumn Information Security Experiment 1 (password and hiding technology)

Attack and defense world mobile--ph0en1x-100

剑指Offer10- I. 斐波那契数列
![Sword finger offer04 Search in two-dimensional array [medium]](/img/c4/002c951f8d914aaea4f4133685ebd1.png)
Sword finger offer04 Search in two-dimensional array [medium]

T430 toss and install OS majave 10.14

Integer case study of packaging

Seven second order ladrc-pll structure design of active disturbance rejection controller

【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】

Sword finger offer14 the easiest way to cut rope

【ManageEngine】IP地址扫描的作用
随机推荐
Openstack node address change
Oh my Zsh + TMUX installation
阿里 & 蚂蚁自研 IDE
2021 autumn Information Security Experiment 1 (password and hiding technology)
idea将web项目打包成war包并部署到服务器上运行
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
自抗扰控制器七-二阶 LADRC-PLL 结构设计
Swift Error Handling
十條職場規則
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
[exercice 7] [principe de la base de données]
Integer case study of packaging
Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
【ManageEngine】IP地址扫描的作用
context. Getexternalfilesdir() is compared with the returned path
GCN thinking - word2vec directly calculates text classification
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
【習題五】【數據庫原理】
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹