当前位置:网站首页>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!");
}
}
}
边栏推荐
- 【习题六】【数据库原理】
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
- Public and private account sending prompt information (user microservice -- message microservice)
- Sword finger offer05 Replace spaces
- Grid connection - Analysis of low voltage ride through and island coexistence
- Swift5.7 扩展 some 到泛型参数
- 写一个简单的nodejs脚本
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
- Everything comes to him who waits
- Simple use and precautions of kotlin's array array and set list
猜你喜欢

Xctf mobile--app3 problem solving

剑指Offer03. 数组中重复的数字【简单】

剑指Offer05. 替换空格

【数据挖掘复习题】

Analysis of a music player Login Protocol

Glide question you cannot start a load for a destroyed activity

Harmonic current detection based on synchronous coordinate transformation

Application of ncnn neural network computing framework in orange school orangepi 3 lts development board

Sword finger offer07 Rebuild binary tree

【综合题】【数据库原理】
随机推荐
Swift5.7 extend some to generic parameters
Sword finger offer04 Search in two-dimensional array [medium]
十條職場規則
Sword finger offer03 Repeated numbers in the array [simple]
Idea packages the web project into a war package and deploys it to the server to run
Using swift language features, write a pseudo-random number generator casually
Eureka自我保护
Differences between initial, inherit, unset, revert and all
[judgment question] [short answer question] [Database Principle]
启用MemCached的SASL认证
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
RedHat5 安装Socket5代理服务器
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
The latest version of blind box mall thinkphp+uniapp
写一个简单的nodejs脚本
Solve the problem of VI opening files with ^m at the end
Public and private account sending prompt information (user microservice -- message microservice)
Sword finger offer10- I. Fibonacci sequence
[combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
Sword finger offer09 Implementing queues with two stacks