Waiting for async/await inside a task

前端 未结 3 753
日久生厌
日久生厌 2020-11-27 15:05

I have this construct in my main(), which creates

var tasks = new List();

var t = Task.Factory.StartNew(
    async () =>
    {
         


        
3条回答
  •  一个人的身影
    2020-11-27 15:40

    It seems like I get desired functionality by Unwrap()ing the task. I'm not quite sure I get the reasoning behind this, but I suppose it works.

    var t = Task.Factory.StartNew(
                async () =>
                    {
                            Foo.Fim();
                            await Foo.DoBar();
                    }).Unwrap();
    

    edit: I've looked for ddescription of Unwrap(): Creates a proxy Task that represents the asynchronous operation of a Task> I thought this was traditionally what the task did, but if I need to call unwrap I suppose that's fine.

提交回复
热议问题