I am a newbie and trying to learn the right way.
Is it acceptable to use a Thread within a constructor to avoid gui(Form) to freeze when an object is created? I will reuse this class often.
class Cmd
{
protected static string parameters;
protected HashSet<string> list_result;
public Cmd( string parameters)
{
Thread Thread1 = new Thread(new ThreadStart(Process1));
Thread1.Start();
Thread1.Join();
}
private void Process1()
{
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/c " + parameters);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
Process process = Process.Start(processStartInfo);
list_result = new HashSet<string>();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
list_result.Add(line);
}
}