Wait for method to finish

后端 未结 3 1692
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 05:25

How can I wait for a method to finish using C#?

3条回答
  •  不知归路
    2020-12-18 05:54

    Unless you're using multiple threads, execution won't continue in the calling code until the method has completed anyway.

    If you are using multiple threads, it really depends on how you're launching the task. For example, you could be using asynchronous delegate execution (foo.BeginInvoke(...)) or the Task Parallel Library, or simply creating a new thread. Each approach has its own way of waiting until the task/thread has completed. Please give us more information and we can help you more, but options may include:

    • Calling EndInvoke on the delegate, passing in the IAsyncResult returned by BeginInvoke
    • Calling Task.Wait (optionally with a timeout)
    • Calling Thread.Join (optionally with a timeout)

提交回复
热议问题