当前位置:网站首页>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!");
}
}
}
边栏推荐
- 剑指Offer06. 从尾到头打印链表
- 剑指Offer10- I. 斐波那契数列
- Integer case study of packaging
- Sqoop1.4.4原生增量导入特性探秘
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
- 写一个简单的nodejs脚本
- Simple use and precautions of kotlin's array array and set list
- 【习题五】【数据库原理】
- Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
- [Exercice 5] [principe de la base de données]
猜你喜欢
并网-低电压穿越与孤岛并存分析
2021 autumn Information Security Experiment 1 (password and hiding technology)
【R】【密度聚类、层次聚类、期望最大化聚类】
How to convert a decimal number to binary in swift
The latest version of lottery blind box operation version
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
idea将web项目打包成war包并部署到服务器上运行
Sword finger offer07 Rebuild binary tree
Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)
Glide question you cannot start a load for a destroyed activity
随机推荐
Kotlin notes - popular knowledge points asterisk (*)
[exercise 7] [Database Principle]
Low code platform international multilingual (I18N) technical solution
【判断题】【简答题】【数据库原理】
Alibaba is bigger than sending SMS (user microservice - message microservice)
RedHat5 安装Socket5代理服务器
Method overloading and rewriting
The foreground uses RSA asymmetric security to encrypt user information
十条职场规则
Nodejs+Express+MySQL实现登陆功能(含验证码)
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
context. Getexternalfilesdir() is compared with the returned path
强大的头像制作神器微信小程序
Project video based on Linu development
【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
I'm too lazy to write more than one character
Integer case study of packaging
【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
Sword finger offer04 Search in two-dimensional array [medium]
Grid connection - Analysis of low voltage ride through and island coexistence