I am new to multithreading in C#. This is what I am trying to do. I have a sql server table
create table dbo.temp(ID smallint not null, textfilename varchar(100) not null,isDone bit not null )
INSERT INTO dbo.temp(1,'textfile1.txt',0)
INSERT INTO dbo.temp(2,'textfile2.txt',0)
INSERT INTO dbo.temp(3,'textfile3.txt',0)
INSERT INTO dbo.temp(4,'textfile4.txt',0)
I have a c# program that Uses the contents of this textfile and updates other database tables and sets isdone=1. I know how to do this singlethread.
public class Program
{
public static void Main()
{
public string filename = "";
try
{
string query = "SELECT ID,textfilename FROM [somedatabase].[dbo].[temp] WITH(NOLOCK) WHERE isdone = 0 ORDER BY ID;";
using (SqlConnection Conn= new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnStr"].ConnectionString))
{
Conn.Open();
using (SqlCommand cmd = new SqlCommand(query, Conn))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
fileid = reader.GetInt16(0).ToString();
filename = reader.GetString(1);
StartProcessingFiles(filename);
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static void StartProcessingFiles(string filename)
{
//some business rules here
//after processing them
//Update [somedatabase].[dbo].[temp] SET isdone=1 where filename=filename
}
}
How can I convert this to multithread say 3 files at a time