c# - Async Await top level handling -
i have 10 sql tables need extract data, process, , insert data table. don't want them in parallel, make use of io time.
i have function:
public async task promoteasync() { try { using (httransdb transactions = new httransdb()) using (zimportmaster importmaster = new zimportmaster()) using (zmasteraddress masteraddress = new zmasteraddress()) { // select out non error rows datatable dt = await httransdb.getvalidrowsasync(this.tableconfig.batchid, this.tableconfig.sourcetablename); // stuff // insert data using (httransdb transactionsdb = new httransdb()) { int result = await transactiondb.bulkcopyasync(dt); } } } catch (exception e) { // log exception , re-throw } }
i run function in foreach loop each table:
public async task promoteload() { // load each batch foreach (var table in this.tables) { await table.promoteasync(); } }
my question is, how call function non async method? task.run
? don't want start new threads, want process keep running while waiting io.
you can start asynchronous work invoking method:
var promotetask = promoteasync();
note returned task represents execution of method.
Comments
Post a Comment