当前位置:网站首页>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!");
}
}
}
边栏推荐
- Record your vulnhub breakthrough record
- context. Getexternalfilesdir() is compared with the returned path
- Huffman coding experiment report
- Harmonic current detection based on synchronous coordinate transformation
- 阿里大于发送短信(用户微服务--消息微服务)
- Seven second order ladrc-pll structure design of active disturbance rejection controller
- Deeply understand the mvcc mechanism of MySQL
- (latest version) WiFi distribution multi format + installation framework
- Grid connection - Analysis of low voltage ride through and island coexistence
- 【习题六】【数据库原理】
猜你喜欢
Alibaba is bigger than sending SMS (user microservice - message microservice)
[problem exploration and solution of one or more filters or listeners failing to start]
Analysis of the influence of voltage loop on PFC system performance
How to convert a decimal number to binary in swift
Integer case study of packaging
剑指Offer03. 数组中重复的数字【简单】
Glide question you cannot start a load for a destroyed activity
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
Xctf mobile--rememberother problem solving
Method overloading and rewriting
随机推荐
Alibaba is bigger than sending SMS (user microservice - message microservice)
Detailed explanation of the most complete constraintlayout in history
Differences between initial, inherit, unset, revert and all
Analysis of a music player Login Protocol
【习题六】【数据库原理】
GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
【習題七】【數據庫原理】
Kung Fu pays off, and learning is done
Sword finger offer04 Search in two-dimensional array [medium]
【ManageEngine】IP地址扫描的作用
Dix règles de travail
Analysis of the influence of voltage loop on PFC system performance
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
【习题五】【数据库原理】
Differences and connections between final and static
[comprehensive question] [Database Principle]
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
Powerful avatar making artifact wechat applet
Xctf mobile--rememberother problem solving
alright alright alright