protected static void CheckpointThread() {
bool start = true;
ArrayList action_list = new ArrayList();
do {
try {
System.Threading.Thread.Sleep(CHECKPOINT_INTERVAL*1000);
} catch(System.Threading.ThreadInterruptedException) {
break;
}
action_list = Interlocked.Exchange(ref _query_list, action_list);
try {
TextWriter tw = null;
if (start) {
//truncate file
tw = new StreamWriter(_checkpoint_file, false);
start = false;
}
else {
//open in append mode
tw = new StreamWriter(_checkpoint_file, true);
}
foreach(SortedList sorted_stat in action_list) {
foreach(object[] curr_result in sorted_stat.Values) {
//also write the checkpoint time
double d = (double) curr_result[0];
string host = (string) curr_result[1];
tw.Write("{0} {1} ", host, d);
}
tw.WriteLine();
}
tw.Close();
} catch (Exception x) {
Console.Error.WriteLine(x);
} finally {
action_list.Clear();
}
} while (_checkpoint_thread_finished == 0);
}
#endif