How can I wait for a method to finish using C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I assume you are asking how to wait for a Code executing on another Thread in your main Thread . For that purpose Thread.Join() method will do what you want.
(A nice tutorial on how to do Multithreading.)
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:EndInvoke
on the delegate, passing in theIAsyncResult
returned byBeginInvoke
Task.Wait
(optionally with a timeout)Thread.Join
(optionally with a timeout)Note: Only works for blocking calls.