gpt4 book ai didi

c# - 如何从按钮异步长进程

转载 作者:太空宇宙 更新时间:2023-11-03 22:35:37 25 4
gpt4 key购买 nike

<分区>

目前我有一个调用函数的按钮,处理时间为 10-20 秒。是否有可能有一些文本,如“请稍候...”,而不是应用程序挂起。

这是我调用函数的按钮:

private void btnExec_Click(object sender, EventArgs e)
{
LongProcess();
}

这是执行时间过长的函数:

 public void LongProcess()
{
DataTable table = new DataTable();

table.Columns.Add("DateTime", typeof(string));
table.Columns.Add("Mass1", typeof(string));
table.Columns.Add("Mass2", typeof(string));
table.Columns.Add("Mass3", typeof(string));

Console.WriteLine(startDate.Value);
Console.WriteLine(endDate.Value);

decimal v = decimal.Parse("1.6345e-008", NumberStyles.Float);
var pattern = @"^""\d+/\d+/\d+ \d+:\d+:\d+ (AM|PM)""\s+-?\d+\s+\d+.?\d+e-\d+";
var regex = new Regex(pattern, RegexOptions.Compiled);

string[] filePaths = Directory.GetFiles(@"C:\\test\\", "*.txt");

var results = new List<string>();

foreach (var file in filePaths)
{
var lines = File.ReadLines(file).Where(x => regex.IsMatch(x));
results.AddRange(lines);
}

foreach (var result in results)
{
string[] words = (result.ToString()).Split(' ');
string date = words[0].Substring(1) + " " + words[1];

DateTime oDate = DateTime.Parse(date);

if (oDate >= startDate.Value && oDate <= endDate.Value)
{
string[] words2 = (words[2].ToString()).Split('\t');
string m1 = words2[2];
string m2 = words2[3];
string m3 = words2[4];
table.Rows.Add(new object[] { oDate.ToString(), m1, m2, m3});

File.WriteAllText(@"C:\\test.csv", sb.ToString());
Console.WriteLine("Done Parsing");
}

任何建议/评论 TIA。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com