I have the following algorithm ,
private void writetodb()
{
using(var reader = File.OpenRead("C:\Data.csv");
using(var parser = new TextFieldParser(reader))
{
//Do some opeartions
while(!parser.EndOfData)
{
//Do operations
//Take 500 rows of data and put it in dataset
Thread thread = new thread(() => WriteTodb(tablename, set));
thread.Start();
Thread.Sleep(5000);
}
}
}
public void WriteTodb(string table, CellSet set)
{
//WriteToDB
//Edit: This statement will write to hbase db in hdinsight
hbase.StoreCells(TableName, set);
}
This method works absolutely fine until 500 mb of data but after that it fails saying Out of memory exception.
I am pretty much sure that it is because of threads but using threads is mandatory and I cant change the architecture.
Can anybody tell me what modifications I have to make in thread programming in the above program to avoid memory exception.