Cannot await OpenAccess method

2 posts, 0 answers
  1. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 21 Mar 2013 Link to this post

    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;
            }



  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 27 Mar 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top