locked
Run a background proccess without blocking the main thread RRS feed

  • Question

  • User-413727468 posted

    Hi,

    I am new to developing with ASP.NET  and C# and I would want to ask the following question:

    I am developing a web site to display reports with three pages .aspx: one to login, another to select the parameters which will be sent to the report and a third page which contains a ReportViewer object to show a Reporting Services remote server report. The third page also contains a button to export the report in a .csv file and then this .csv file is sent to the user by email.

    My problem is that the report is huge and the export process takes a very long time blocking the web page so the user cannot continue navigating. I have done a test with a background thread but it blocks the page (main thread) too. The  background thread is created in "onclick" method of the button.

        Thread email = new Thread(delegate()
        {
            String nombreFichero = ExportarInforme(); //convert to .csv file
            enviarCorreo(); //send email with the attachment
    
        });
        email.IsBackground = true;
        email.Start();
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Correo enviado');", true);

    I have also used a BackgroundWorker object but it still blocks the page.

    My idea is to click the button and open a new tab. The background thread (file export) should be run in this new tab unblocking the web page allowing the user to navigate through it. Is this possible? How could it be done?

    Thanks in advance.

    Best regards,

    Lucía

    Friday, May 6, 2016 8:42 AM

Answers

  • User527778624 posted

    Hi,

    Check this site, you can use any of the libraries or simple code:

    http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2016 12:03 PM
  • User-1780421697 posted

    You need to use fluent scheduler ,easy and simple to use,without worring of managing threads etc.
    https://fluentscheduler.codeplex.com/
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2016 5:58 PM
  • User-2057865890 posted

    Hi Lucia,

    You could consider using some open source like Hangfire, it is completely free for commercial use.

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 11, 2016 8:28 AM

All replies

  • User527778624 posted

    Hi,

    Check this site, you can use any of the libraries or simple code:

    http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2016 12:03 PM
  • User-1780421697 posted

    You need to use fluent scheduler ,easy and simple to use,without worring of managing threads etc.
    https://fluentscheduler.codeplex.com/
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2016 5:58 PM
  • User-2057865890 posted

    Hi Lucia,

    You could consider using some open source like Hangfire, it is completely free for commercial use.

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 11, 2016 8:28 AM