lu
2024-10-28 510643d77bd33d73bb9afae041120941e978b91c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media.Animation;
using DevExpress.Internal.WinApi.Windows.UI.Notifications;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.Import.OpenXml;
using DevExpress.XtraTreeList.Data;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
 
namespace Gs.DevApp.TestForm
{
    public partial class XtraForm1 : XtraForm
    {
 
        //https://www.cnblogs.com/China3S/p/3452008.html
        public XtraForm1()
        {
            InitializeComponent();
            //dddddddd();
 
            //await Task.Run(() =>
            //{
 
            //});
        }
 
        private async void dddddddd() {
 
            
            UcLoading _loading = new UcLoading();
            var pgq = new PageQueryModel(1, 999999, "item_name", "asc", "",
                        " and fforbidstatus='A'");
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                //var strReturn = await UtilityHelper.HttpPostAsync("",
                //    "MesItemsManager/GetListPageByLook", json);
                //var rtn = UtilityHelper.ReturnToList(strReturn);
                //var dt = rtn.rtnData;
 
                await csd();
               
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
            _loading.Stop();
        }
 
        private async Task<int> csd()
        {
            int c = 0;
            //await Task.Delay(1000);
            await Task.Run(() =>
            {
                for (int i = 0; i < 10000; i++)
                {
                    c = c + i;
                    if (richTextBox1.InvokeRequired)
                    {
                        richTextBox1.BeginInvoke(new Action(() =>
                        {
                            richTextBox1.Text = c.ToString();
                        }));
                    }
                    else
                    {
                        richTextBox1.Text = c.ToString();
                    }
                }
            
            });
            return c;
 
        }
        private  void simpleButton1_Click_1(object sender, EventArgs e)
        {
            dddddddd();
        }
 
        
        private async void simpleButton2_Click(object sender, EventArgs e)
        {
            UcLoading _loading = new UcLoading();
            string url = "http://localhost:5263/";
            try
            {
                string result = await GetHttpResponseAsync(url);
                Console.WriteLine(result);
                richTextBox1.Text = result;
            }
            catch (WebException ex)
            {
                richTextBox1.Text = ex.Message;
            }
            _loading.Stop();
        }
 
        private static async Task<string> GetHttpResponseAsync(string url)
        {
            string param = "{}";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
           
            request.Method = "POST";
            request.ContentType = "application/json";
            //request.Headers.Add("token", GetBasicAuthTicket());
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;
 
 
            //StreamWriter requestStream = null;
            //requestStream = new StreamWriter(request.GetRequestStream());
            //requestStream.Write(param);
            //requestStream.Close();
 
            using (Stream requestStream = await request.GetRequestStreamAsync())
            {
                byte[] dataBytes = Encoding.UTF8.GetBytes(param);
                await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length);
            }
 
 
            using (WebResponse response = await request.GetResponseAsync())
            using (Stream responseStream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
            {
                return await reader.ReadToEndAsync();
            }
        }
    }
}