i have a program that uses several background workers
that continuously load and read text files (size can up to 1MB)
and update to oracle database.
The problem i am having is whenever the background worker is reading files, the main thread
will become not responding
which it should not be. Is this the default behaviour when reading files, is there any way to solve it?
Thanks, any help will be very much appreciated.
Update: [brief view of my program code]
private void program_Load(object sender, EventArgs e)
{
bw1.RunWorkerAsync();
bw2.RunWorkerAsync(); //same function as bw1 but different directory
}
private void bw1_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
Thread.Sleep(5000);
bw1.ReportProgress(0);
}
}
private void bw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
directoryInfo = /* directory url */;
files = directoryInfo .GetFiles();
foreach (FileInfo file in files)
{
/*
read file line by line
load data into database
update file loading status to UI
*/
}
}