Page 1 of 1

Asynchronous BeginFill() does not return immediately

Posted: Wed 09 Jan 2013 16:01
by tgrossjean
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/stat ... async.html

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

*/
MessageBox.Show("Returned from BeginFill()");
}

Re: Asynchronous BeginFill() does not return immediately

Posted: Thu 10 Jan 2013 15:27
by Pinturiccio
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.

Re: Asynchronous BeginFill() does not return immediately

Posted: Thu 10 Jan 2013 16:33
by tgrossjean
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.

Re: Asynchronous BeginFill() does not return immediately

Posted: Fri 11 Jan 2013 15:30
by Pinturiccio
We will investigate the issue and notify you about the results as soon as possible.

Re: Asynchronous BeginFill() does not return immediately

Posted: Tue 12 Mar 2013 15:43
by Pinturiccio
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.