I'm a beginner to C# & I'm using HttpWebRequest to obtain a web page source. Well I'm using regex to scan the source code for content inside the html element . Basically the regex looks like this in C#.
Match m = Regex.Match(result, @"^(.*?<form .*?>(.*?)</form>.*?)+$", RegexOptions.Singleline);
The only problem that i'm facing is that until this process is completed my application freezes. Will background threading help me ? if so could you please be kind to help me out with a snippet for implementing it ? .. It will be great if i can display a progress bar or something for the user.
private void button1_Click(object sender, EventArgs e)
{
Thread backgroundThread = new Thread(
new ThreadStart(() =>
{
Match m = Regex.Match(result, @"^(.*?<form .*?>(.*?)</form>.*?)+$", RegexOptions.Singleline);
foreach (var capture in m.Groups[2].Captures)
{
forms.Add(capture.ToString());
}
MessageBox.Show("Thread completed!");
if (progressBar.InvokeRequired)
progressBar.BeginInvoke(new Action(() => progressBar1.Value = 0));
}
));
backgroundThread.Start();
}