ActionQueue queue = new ActionQueue();
queue.addAction(() => {
// Code to run
});
ActionQueue fileAccessQueue = new ActionQueue();
fileAccessQueue.AddAction(() => {
using (StreamWriter w = File.AppendText(filename))
{
w.WriteLine(content);
}
});
string content = "";
Task t = fileAccessQueue.AddAction(() => {
content = File.ReadAllText(filename);
});
Task.WaitAll(t); // wait for any reading/writing actions in queue
return content;