当前位置:网站首页>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!");
}
}
}
边栏推荐
- Seven second order ladrc-pll structure design of active disturbance rejection controller
- Enable SASL authentication for memcached
- Sword finger offer04 Search in two-dimensional array [medium]
- Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
- ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
- Social community forum app ultra-high appearance UI interface
- Huffman coding experiment report
- 【習題七】【數據庫原理】
- Simple use and precautions of kotlin's array array and set list
- 阿里大于发送短信(用户微服务--消息微服务)
猜你喜欢

Huffman coding experiment report

自抗扰控制器七-二阶 LADRC-PLL 结构设计

T430 toss and install OS majave 10.14

记录自己vulnhub闯关记录

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

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

【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素

Integer case study of packaging

Powerful avatar making artifact wechat applet

Record your vulnhub breakthrough record
随机推荐
The solution to change the USB flash disk into a space of only 2m
【習題五】【數據庫原理】
Export the entire Oracle Database
Nodejs+Express+MySQL实现登陆功能(含验证码)
Define a list, store n integers, and calculate the length, maximum value, minimum value and average value of the list
剑指Offer10- I. 斐波那契数列
[Exercice 5] [principe de la base de données]
Method overloading and rewriting
Harmonic current detection based on synchronous coordinate transformation
剑指Offer07. 重建二叉树
context. Getexternalfilesdir() is compared with the returned path
[ArcGIS user defined script tool] vector file generates expanded rectangular face elements
基于同步坐标变换的谐波电流检测
Record your vulnhub breakthrough record
[combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
Openstack node address change
studio All flavors must now belong to a named flavor dimension. Learn more
With pictures and texts, summarize the basic review of C language in detail, so that all kinds of knowledge points are clear at a glance?
GCN thinking - word2vec directly calculates text classification
Seven second order ladrc-pll structure design of active disturbance rejection controller