I have a program that loads a file, MD5 Hash’es it, and outputs the Hash to a new text file. It works well, but I have one issue. After it outputs the file successfully, the console window doesn’t close automatically, and as a result, one must close the window in order for the program to exit. How would I make it exit on its own?
code:
string hash = GetHash("1.txt");
Console.WriteLine("Hash: {0}", hash);
Console.ReadKey();
}
public static string GetHash(string pathSrc)
{
string pathDest = "copy_" + pathSrc;
File.Copy(pathSrc, pathDest, true);
String md5Result;
StringBuilder sb = new StringBuilder();
MD5 md5Hasher = MD5.Create();
using (FileStream fs = File.OpenRead(pathDest))
{
foreach (Byte b in md5Hasher.ComputeHash(fs))
sb.Append(b.ToString("x2").ToLower());
}
md5Result = sb.ToString();
File.Delete(pathDest);
TextWriter tw = new StreamWriter("8.txt");
tw.WriteLine(md5Result);
tw.Close();
return md5Result;
Have you tried getting rid of the Console.ReadKey()?