private static string GetTempFileName(string original, bool makeTempFile) {
string result=null;
if (original==null) {
result=Path.GetTempFileName();
} else {
int counter=0;
int suffixSeed=DateTime.Now.Second;
while (result==null) {
counter+=1;
string newName=string.Format("{0}.{1}{2}.tmp", original, suffixSeed, counter);
if (!File.Exists(newName)) {
if (makeTempFile) {
try {
// Try and create the file.
using (FileStream stream=File.Create(newName)) {
}
result=newName;
} catch {
suffixSeed=DateTime.Now.Second;
}
} else {
result=newName;
}
}
}
}
return result;
}