Asynchronous BeginFill() does not return immediately

Asynchronous BeginFill() does not return immediately

Postby tgrossjean » Wed 09 Jan 2013 16:01

A asynchronous call to PgSqlDataTable.BeginFill() does not return immediately, as expected, thus beeing rather useless, as it is blocking the working thread of our Application until the database has completed the given command.

### Example, c# ####

private void Test()
{
PgSqlDataTable myDataTable = new PgSqlDataTable();

myDataTable.Connection = EdGlobals.Connection;
myDataTable.SelectCommand = EdGlobals.Connection.CreateCommand();
myDataTable.SelectCommand.CommandText = "SELECT pg_sleep(20)";
myDataTable.NonBlocking = true;
IAsyncResult aRes = myDataTable.BeginFill(null, null);

//Here, the CURRENT THREAD hangs for 20 seconds, because
//the "BeginFill()"-Method doesn't return immediately, as expected

//Instead of the command "SELECT pg_sleep(20)" you can also try
//"SELECT * from my_very_long_executing_pgsql_function()"
//with a pgsql-Function of your own that does a lot of work before returning

/*Have a look at:
*
http://www.postgresql.org/docs/9.2/static/libpq-async.html

Following the postgresql-documentation, the asynchronous functions should return immediately

*/
MessageBox.Show("Returned from BeginFill()");
}
tgrossjean
 
Posts: 6
Joined: Fri 26 Mar 2010 09:48
Location: Germany

Re: Asynchronous BeginFill() does not return immediately

Postby Pinturiccio » Thu 10 Jan 2013 15:27

Prior to filling the table, you should execute a command for metadata reading (to get information about columns) for table columns creation.

In case of the query "SELECT pg_sleep(20)" the server will return the result only in 20 seconds, and only then asynchronous table filling will start.
Pinturiccio
Devart Team
 
Posts: 2026
Joined: Wed 02 Nov 2011 09:44

Re: Asynchronous BeginFill() does not return immediately

Postby tgrossjean » Thu 10 Jan 2013 16:33

Your answer is exactly my description of the problem:

"...the server will return the result only in 20 seconds, and only then asynchronous table filling will start..."

Yes, and this would happen with a long-running sql-query, too.

###

Again:

In your Implementation, the call to datatable.BeginFill() does not return immediately, but is blocking the current thread until the database server answers! - That's not asynchronous behaviour.

Usually, asynchronous calls return immediately or after a given timeout, while the asynchronous thread does his work and then signals to the calling thread.

THE CALLING THREAD IS NOT BLOCKED
.

---

In your implementation of datatable.BeginFill(),the calling thread IS Blocked.

That's the problem.
tgrossjean
 
Posts: 6
Joined: Fri 26 Mar 2010 09:48
Location: Germany

Re: Asynchronous BeginFill() does not return immediately

Postby Pinturiccio » Fri 11 Jan 2013 15:30

We will investigate the issue and notify you about the results as soon as possible.
Pinturiccio
Devart Team
 
Posts: 2026
Joined: Wed 02 Nov 2011 09:44

Re: Asynchronous BeginFill() does not return immediately

Postby Pinturiccio » Tue 12 Mar 2013 15:43

When PgSqlDataTable.BeginFill is executed, dotConnect for PostgreSQL has to create columns for a table, and get RecordCount, if the QueryRecordCount property equals 'True'.
This behavior was planned initially and will not be changed.
Pinturiccio
Devart Team
 
Posts: 2026
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL