I'm having a bit of problem dealing with an async task that generates a temperature profile.
public static async Task genLotProfile(string lotno,string filename, string datch)
{
int count = 0;
while (true)
{
count += 1;
//Move this following code to new method
var csv = new StringBuilder();
if (!File.Exists(filename))
{
File.Create(filename);
}
Tprofile temp = getLogData(datch);
if (count == 1)
{
var header = string.Format("Lotno,Temperature,Date,DataChannel");
csv.AppendLine(header);
}
var newLine = string.Format("{0},{1},{2},{3}", lotno,temp.temperature, temp.date, temp.dataChannel);
csv.AppendLine(newLine);
if (!File.Exists(filename))
{
File.WriteAllText(filename, csv.ToString());
}
File.AppendAllText(filename, csv.ToString());
//task delay
await Task.Delay(30000);
}
}
And then I call it in the other form on an enter button click function.
//Temperature profile
string filename = MainWindow.getTempProfileName(MainWindow.datachannel, lotnoTBX.Text);
MainWindow.genLotProfile(lotnoTBX.Text, filename, MainWindow.datachannel);
What are the conventions of killing a task in my case?