This code is the fragment of a method that reads a text file and sends its contents line by line, where each sent line receives a receipt acknowledgment. I would like to erase the sent line from the file so that it receives its acknowledgment of receipt, so that if the transmission is interrupted in the middle of the file, I do not send the lines that have already been sent, thus avoiding to duplicate the information received by the equipment. Could you please help me with this?
//Path ex : "/home/dhnqe/DataContainer.txt"
if (File.Exists(path))
{
StreamReader file = new StreamReader(path);
int numeroLinhas = File.ReadAllLines(path).Length;
while ((linha = file.ReadLine()) != null)
{
linha = string.Format(linha + "\r\n");
for (int i = 0; i< 3; i++)
{
controle = false;
SendLineByRadio(address, line); //Enviar Linha
int start = Environment.TickCount;
do
{
...
...
} while (!controle && !timeout);
if (controle)
{
if (Confirmation == "ReceiveOK")//Caso receba a confirmação
{
Console.WriteLine("Data Sent = OK");
clearData();
controle = false;
//INSERIR FUNCAO PARA APAGAR LINHA ENVIADA DO ARQUIVO TXT
i = 10;
}
}
if (timeout)
{
Console.WriteLine("Data Sent = Confirmation Timeout");//Caso não recebe a confirmacao
clearData();
controle = true;
if (i == 2)
{
Console.WriteLine("Error: Response not received");
clearData();
Thread.CurrentThread.Abort();
}
}
}
}