Async page in aspx

0

I am developing a web page with .NET

I have a method to send emails which I want to do asynchronously. So far everything has been done correctly, but in the design of the .aspx views I have the following problem.

I have a MasterPage structure - > Page where the Page can be declared as asynchronous but on the other hand the Master is not. I declare this as follows.

<%@ Page Title="" Language="C#" MasterPageFile="~/Administration/Administration.Master" AutoEventWireup="true" CodeBehind="GestionUsuarios.aspx.cs" Inherits="Administration.GestionUsuarios" Async="true"%>

In Administration.Master, however, it is not possible to declare it as asynchronous. So the method continues to run as synchronous.

I can not find a solution to this.

Thank you.

    
asked by jld 05.07.2018 в 10:07
source

1 answer

1

Why not simply in the event in which you intend to send the mail calls an asynchronous method, in this define a thread, you configure it and then you launch it, see an example:

    private void MiMetodoSincrono(string parametroX)
    {
                    Thread currentThread = new Thread(() => MiMetodoAsincrono(parametros));
                    currentThread.Start();/*aqui disparas el hilo para que envie el correo*/
                    //codigo  /*este codigo continua en el hilo actual y no va a esperar a que termine el envio del correo*/
    }

    public async void MiMetodoAsincrono(parametros) //método asincrono
    {
                    //codigo de enviar correo
    }

I hope it serves you!

    
answered by 10.07.2018 / 17:02
source