This is a migrated thread and some comments may be shown as answers.

Cannot await OpenAccess method

1 Answer 76 Views
BusyIndicator
This is a migrated thread and some comments may be shown as answers.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 22 Mar 2013, 01:59 AM
Hi
See following line of code in bold that is commented out.  I get the following compile error:
"Cannot await Telerik.OpenAccess.Metadata.MetadataContainer"
If I use "await Task.Delay(2000);"  as show below it works great.  However I can't rely on a fixed amount of time.  Is there any problem awaiting OpenAccess methods or am I doing something wrong?

Thanks
Rich

        public async Task<MetadataContainer> GetSchema(RadBusyIndicator BusyIndicator, ConnectionInfo connInfo, 
            bool TablesAndViews, bool StoredProcedures, bool Indexes)
        {
            ISchemaReader reader = GetSchemaReader(connInfo);
            String[] schemas = reader.GetSchemas();
            SchemaReadParameters readParameters = new SchemaReadParameters(schemas);
            readParameters.Indexes = Indexes;
            readParameters.StoredProcedures = StoredProcedures;
            readParameters.TablesAndViews = TablesAndViews;
            BusyIndicator.IsBusy = true;
            //MetadataContainer metadataContainer = await reader.GetSchema(readParameters); 
            MetadataContainer metadataContainer = reader.GetSchema(readParameters);   
            await Task.Delay(2000);
            BusyIndicator.IsBusy = false;
            return metadataContainer;
        }



1 Answer, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 27 Mar 2013, 01:20 PM
Hi Richard,

The ISchemaReader.GetSchema() method doesn't return a Task and is not awaitable. That's why the code you provided won't compile. In order to make to method asynchronous you will have to create a new Task that handles the GetSchema() method. Here is sample code:
var task = Task<MetadataContainer>.Factory.StartNew(() => reader.GetSchema(readParameters));
MetadataContainer metadataContainer = await task;


Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
BusyIndicator
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Share this question
or