Asynchronous Threading in asp.net c# website

  • Thread starter Thread starter Spunny
  • Start date Start date
S

Spunny

Guest
Hi,

We developed asp.net website using visual studio 2012 which uses asynchronous calls to db to generate pdf files. It was working fine. The whole process of running SSRS report and generating PDF files takes 4 hours to generate 2000 pdf files. Users start the generation process in web site and they log off. Since it is asynch process, files get generated.

Now we upgraded to visual studio 2017 and when I run the site, process starts (not sure it is sync or async process). The moment I log out of the site, generation of files stop. In db, session shows that it is not running.

Here is the code:

public void GenerateFiles(string TargetFolder, string ScriptsFolder)

{

SqlConnection connection = new SqlConnection(ConnectionString + ";Asynchronous Processing=true");


SqlCommand command = new SqlCommand();

command.Connection = connection;

command.CommandType = CommandType.StoredProcedure;

connection.Open();


command.Parameters.Clear();

command.CommandText = "StoredProcedure1";

command.Parameters.Add("@TargetFolder ", SqlDbType.VarChar).Value = TargetFolder;

command.Parameters.Add("@ScriptsFolder ", SqlDbType.VarChar, 1000).Value = ScriptsFolder;

}


command.BeginExecuteNonQuery(AsynchronousNonQuery_ClearSessionCallBack, command);


}


private void AsynchronousNonQuery_ClearSessionCallBack(IAsyncResult asyncResult)

{

try

{

SqlCommand command = asyncResult.AsyncState as SqlCommand;

command.EndExecuteNonQuery(asyncResult);

command.Parameters.Clear();

command.CommandText = "uspProcessesClearRunningPortalFunction";

command.CommandType = CommandType.StoredProcedure;

command.ExecuteNonQuery();

command.Connection.Close();

}

catch (Exception e)

{

Logging.LogError(e, e.Message, System.Diagnostics.EventLogEntryType.Error);

}

}



Looks like AsynchronousNonQuery_ClearSessionCallBack never gets called. Why is above process not working as async with new .net framework.

Connection Object Details:

connection
{System.Data.SqlClient.SqlConnection}
AccessToken: null
CanRaiseEvents: true
ClientConnectionId: {5bf674a0-7ae5-444c-b6fd-b721aa07b2c2}
ConnectionString: "Data Source=db;Initial Catalog=ds1;User ID=xxxx;Asynchronous Processing=true"
ConnectionTimeout: 15
Container: null
Credential: null
DataSource: "db"
Database: "ds1"
DbProviderFactory: {System.Data.SqlClient.SqlClientFactory}
DesignMode: false
Events: {System.ComponentModel.EventHandlerList}
FireInfoMessageEventOnUserErrors: false
PacketSize: 8000
ServerVersion: "13.00.5366"
Site: null
State: Open
StatisticsEnabled: false
WorkstationId: "myworkstationID"

COmmand object:

System.Data.SqlClient.SqlCommand}
CanRaiseEvents: true
ColumnEncryptionSetting: UseConnectionSetting
CommandText: "uspSP1"
CommandTimeout: 30
CommandType: StoredProcedure
Connection (System.Data.Common.DbCommand): {System.Data.SqlClient.SqlConnection}
Connection: {System.Data.SqlClient.SqlConnection}
Container: null
DbConnection: {System.Data.SqlClient.SqlConnection}
DbParameterCollection: {System.Data.SqlClient.SqlParameterCollection}
DbTransaction: null
DesignMode: false
DesignTimeVisible: true
Events: {System.ComponentModel.EventHandlerList}
Notification: null
NotificationAutoEnlist: true
Parameters (System.Data.Common.DbCommand): {System.Data.SqlClient.SqlParameterCollection}
Parameters: {System.Data.SqlClient.SqlParameterCollection}
Site: null
Transaction (System.Data.Common.DbCommand): null
Transaction: null
UpdatedRowSource: Both

Continue reading...
 
Back
Top