Async, await for running process that executes SSRS report and generates pdf 1000 times

Spunny 326 Reputation points
2023-07-13T19:56:04.0066667+00:00

Hi,

I have API end point that gets called from another service(bl1).

[HttpGet]

[Route("createfile")]

public void createsfile(string param1, string param2)

{

//asynchronous call to bl1 method

 var files = new bl1();

 files.generateFiles(param1, param2);

 //send message to the caller that file creation process started immediately.

}

New Service (bl1)

public void generatefiles (string param1, string param2)

{

//loop through accounts that were retrieved from database

foreach (int act in actlist)

{

      //generate stream by calling SSRS web request.

      
 try
            {
                HttpClient client = new HttpClient(new HttpClientHandler()
                { UseDefaultCredentials = true,/* PreAuthenticate = false  */});

                Stream theStream =  await client.GetStreamAsync(new Uri(reportUrl));
                using (var memoryStream = new MemoryStream())
                {
                    theStream.CopyTo(memoryStream);
                    System.IO.File.WriteAllBytes(pFileName, memoryStream.ToArray());
                }
            }
            catch (Exception ex)
            {
                string he = "routine";
            }
 }

}

From this end point, we need to call another service say bl1 (business logic) that actually generates 2000 files. What I want is when request is made to the end point, it should start bl1 process asynchronously and immediately go back to caller with message that 'process started'

That bl1 process should be asynchronous loop through accounts and generate pdf for all accounts ( may be 1000 times)

How can I do without using await or async. Only main end point needs to be async because it needs to be started on new thread and main thread not to worry about it.

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
326 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Spunny 326 Reputation points
    2023-07-18T18:17:55.8866667+00:00

    Hi Bruce,

    I tried as you suggest. Fire and Forget. But after 2 hours looks like it is timing out. I am accessing SSRS report using URL. It comes back saying, SSRS server not found.

    0 comments No comments

  2. Lan Huang-MSFT 29,166 Reputation points Microsoft Vendor
    2023-07-20T08:31:44.04+00:00

    Hi @Spunny,I think you can check the SSRS trace log to see details about this error. The path of the trace log is generally \Microsoft SQL Server\MSRS12.<instancename >\Reporting Services\LogFiles.For more information, see Reporting Services Log Files and Sources.

    If it is a timeout, it may be the reason for the timeout configuration, you can check the following configuration:

    https://stackoverflow.com/a/55307294


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.