Currently I have a button that calls a function and has a processing time of 10-20 secs. Is it possible to have some text like "please wait..." rather than the application getting hang.
Here is button where I call my function:
private void btnExec_Click(object sender, EventArgs e)
{
LongProcess();
}
And this is the function that executes too long:
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");
}
Any suuggestion/comments TIA.