Oracle Client vs. Task-based Asynchronous Pattern (async/await)

前端 未结 3 1332
闹比i
闹比i 2021-01-12 07:53

I\'d like to write a bunch of methods querying the Oracle Database in the async/await way. Since ODP.NET seems to support neither awaitable *Async methods nor Begin/EndOpera

3条回答
  •  庸人自扰
    2021-01-12 08:09

    I'm using this

    public static class TaskHelper
    {
        public async static Task AsAsync(Func function, TaskCreationOptions taskCreationOptions = TaskCreationOptions.None)
        {
            return await Task.Factory.StartNew(function, taskCreationOptions);
        }
    
        public async static Task AsAsync(Action action, TaskCreationOptions taskCreationOptions = TaskCreationOptions.None)
        {
            await Task.Factory.StartNew(action, taskCreationOptions);
        }
    }
    

    Any synchronous function can be made asynchronous and you can await of it.

提交回复
热议问题