generate an asynchronous task and return sight without waiting for it .net

3

I am wanting to perform an asynchronous method but I have the problem that, although it is performed asynchronously, it does not return the value until it does not end. I need you to return your sight and continue even if the task is not finished

        Thread oThread = new Thread(ProtocolizacionS.ActualizarProtocolizados);

        oThread.IsBackground = true;

        //// Start the thread
        oThread.Start();
        //while (!oThread.IsAlive) ;


        var devuelta = Proyecto.ListadoVista(user.Login, programaCodigo, expedienteNro, expedienteAno, beneficiario, estadoCodigo, titulo);


        return Json(devuelta, JsonRequestBehavior.AllowGet);
    
asked by Nicolás Kuglien 01.06.2016 в 00:06
source

1 answer

1

Basically, you can use the Task.Yield () that would be in the following way (assuming it is done with the click of a button event):

async void boton_Click(object sender, EventArgs e)
 {
      await Task.Yield(); // Esto hace que se procese en segundo planoMake us async right away

      return Proyecto.ListadoVista(user.Login, programaCodigo, expedienteNro, expedienteAno, beneficiario, estadoCodigo, titulo);
 }
    
answered by 02.06.2016 в 17:51