AsyncAwaitDemo2/Form1.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Diagnostics;
using System.Net.Http;
using System.Security.Policy;
using Utils;

namespace AsyncAwaitDemo2
{
    public partial class Form1 : Form
    {
        private string _urlPreheat = "http://localhost:5028/Test/ForPreheat";
        private string _url = "http://localhost:5028/Test/Get";
        private int _index1 = 1; //测试时请快速连续点击5次button1
        private int _index2 = 1; //测试时请快速连续点击5次button2
        private Stopwatch _sw1;
        private Stopwatch _sw2;

        public Form1()
        {
            InitializeComponent();
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            Request(_urlPreheat); //预热
            await RequestAsync(_urlPreheat); //预热
            Log("==== 预热请求结束 ====================================");
        }

        #region Log
        private void Log(string msg)
        {
            msg = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}  {msg}\r\n";

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action(() =>
                {
                    txtLog.AppendText(msg);
                }));
            }
            else
            {
                txtLog.AppendText(msg);
            }
        }
        #endregion

        private async void button1_Click(object sender, EventArgs e)
        {
            await Task.Delay(1000); //为了能1秒内快速点击几次

            Log("==== 同步请求开始 ====================================");
            if (_index1 == 1) _sw1 = Stopwatch.StartNew();

            Request(_url);

            if (_index1 == 5)
            {
                _sw1.Stop();
后面还有 40 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。