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()");
}
Asynchronous BeginFill() does not return immediately
-
- Posts: 6
- Joined: Fri 26 Mar 2010 09:48
- Location: Germany
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Asynchronous BeginFill() does not return immediately
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.
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.
-
- Posts: 6
- Joined: Fri 26 Mar 2010 09:48
- Location: Germany
Re: Asynchronous BeginFill() does not return immediately
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.
"...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.
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Asynchronous BeginFill() does not return immediately
We will investigate the issue and notify you about the results as soon as possible.
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Asynchronous BeginFill() does not return immediately
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.
This behavior was planned initially and will not be changed.