0

I have several functions to make a data injection to two web services, everything is well separated, but when I want to call the following method, it sends the following error:

Start may not be called on a continuation task

and the data injection is finished, if someone could help me

public async Task DatosEnvioAsync()
        {
            string cnn = ConfigurationManager.ConnectionStrings["prueba"].ConnectionString;
            using (SqlConnection conexion = new SqlConnection(cnn))
            {
                conexion.Open();

                string consulta = "SELECT Nombre,Empresa FROM SamsaraVehiculos";
                using (SqlCommand cmd = new SqlCommand(consulta, conexion))
                {
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader rd = cmd.ExecuteReader();

                    try
                    {
                        List<Task> tasks = new List<Task>();
                        while (rd.Read())
                        {
                            string Vehiculo = rd["Nombre"].ToString();
                            string path = Application.StartupPath + "\\InterfazAssistCargo\\";
                            string path2 = Application.StartupPath + "\\InterfazQS3\\";

                            string[] Valores = { Vehiculo, path };
                            string[] Valores2 = { Vehiculo, path2 };

                            var task = IntroducirValoresTask(Valores)
                                            .ContinueWith(t => IntroducirValoresTask(Valores2));
                            task.Start();
                            tasks.Add(task);

                        }

                        await Task.WhenAll(tasks);
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }
                }

            }
        }

this is the function that calls automatic

private Task IntroducirValoresTask(string[] pValores)
{
    string[] valores = pValores;

    return new Task(async () =>
    {
        Automatico(valores);
        await Task.Delay(2000);
    });
}

How could I do this thread-safe method?

 private void Automatico(object parametros)
    {
        string[] valor = (string[])parametros;
        ProcessStartInfo infoAuto = new ProcessStartInfo();

        infoAuto.FileName = "ProcesoAutomatico.exe";
        infoAuto.WorkingDirectory = valor[1];

        infoAuto.Arguments = Convert.ToString(valor[0]);

        Process proc = Process.Start(infoAuto);

    }

0 Answers0