For such large scale operations i used to use SQLite in an order that i was doing something like SQLiteDB.Query('update table');
and after all those update table i did Commit();
And it ended up way faster.
I cannot know what is the API used inside WriteToTable but if your DB can do it i suggest you build a sql script with all those updates and shove it inside the db.
As for threading i use:
private readonly object lockObject = new object();
volatile int jobCount;
private bool Stopped;
private void btnGo_Click(object sender, EventArgs e)
{
btnGo.Enabled = false;
ThreadPool.QueueUserWorkItem(new WaitCallback(Start));
}
private void Start(object obj)
{
jobCount = 0;
Stopped = false;
for (int i = 0; i < Environment.ProcessorCount; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(execute),null);
jobCount++;
}
lock (lockObject)
{
while (jobCount > 0)
{
Monitor.Wait(lockObject);
}
}
ThreadStart finisher = new ThreadStart(Finish);
finisher.Invoke();
}
private void execute(object obj)
{
while (!Stopped)
{
Thread.Yield();
}
Decreace();
}
private void Decreace()
{
lock (lockObject)
{
jobCount--;
Monitor.Pulse(lockObject);
}
}
private void Finish()
{
Thread.Yield();
btnGo.Enabled = true;
GC.Collect();
Application.DoEvents();
}
Edit: forgot to declare and initialize Stopped variable :P
Edit2: Changed Code to assume not within a form (i.e finisher.Invoke())