Click here to Skip to main content
15,891,905 members
Home / Discussions / C#
   

C#

 
AnswerRe: Factory pattern: issue with this definition "let subclass decide which class to instantiate." Pin
Eddy Vluggen5-Apr-17 2:54
professionalEddy Vluggen5-Apr-17 2:54 
QuestionTask.Wait() -Why?? Pin
Kevin Marois4-Apr-17 6:54
professionalKevin Marois4-Apr-17 6:54 
AnswerRe: Task.Wait() -Why?? Pin
Pete O'Hanlon4-Apr-17 7:00
mvePete O'Hanlon4-Apr-17 7:00 
GeneralRe: Task.Wait() -Why?? Pin
Kevin Marois4-Apr-17 7:19
professionalKevin Marois4-Apr-17 7:19 
GeneralRe: Task.Wait() -Why?? Pin
Pete O'Hanlon4-Apr-17 7:26
mvePete O'Hanlon4-Apr-17 7:26 
GeneralRe: Task.Wait() -Why?? Pin
Richard Deeming4-Apr-17 7:38
mveRichard Deeming4-Apr-17 7:38 
GeneralRe: Task.Wait() -Why?? Pin
Pete O'Hanlon4-Apr-17 7:40
mvePete O'Hanlon4-Apr-17 7:40 
AnswerRe: Task.Wait() -Why?? Pin
Richard Deeming4-Apr-17 7:48
mveRichard Deeming4-Apr-17 7:48 
There are very few situations where it's necessary to block the current thread until a task has completed. The only obvious one that comes to mind is when you're writing a console application, and you want to use async code. And with .NET 4.5 or higher, it's usually better to call task.GetAwaiter().GetResult() rather than task.Wait(), to avoid having any exceptions wrapped in an AggregateException.
C#
static class Program
{
    static void Main()
    {
        MainAsync().GetAwaiter().GetResult();
    }
    
    static async Task MainAsync()
    {
        ...
    }
}

But in most cases, there's usually a better option than blocking the current thread.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Task.Wait() -Why?? Pin
Kevin Marois4-Apr-17 7:52
professionalKevin Marois4-Apr-17 7:52 
GeneralRe: Task.Wait() -Why?? Pin
Richard Deeming4-Apr-17 8:04
mveRichard Deeming4-Apr-17 8:04 
GeneralRe: Task.Wait() -Why?? Pin
Tridip Bhattacharjee5-Apr-17 23:30
professionalTridip Bhattacharjee5-Apr-17 23:30 
GeneralRe: Task.Wait() -Why?? Pin
Richard Deeming6-Apr-17 1:30
mveRichard Deeming6-Apr-17 1:30 
Questionin which scenario people use factory design patter Pin
Tridip Bhattacharjee4-Apr-17 1:58
professionalTridip Bhattacharjee4-Apr-17 1:58 
AnswerRe: in which scenario people use factory design patter Pin
Eddy Vluggen4-Apr-17 2:29
professionalEddy Vluggen4-Apr-17 2:29 
GeneralRe: in which scenario people use factory design patter Pin
Tridip Bhattacharjee4-Apr-17 3:48
professionalTridip Bhattacharjee4-Apr-17 3:48 
GeneralRe: in which scenario people use factory design patter Pin
Pete O'Hanlon4-Apr-17 4:14
mvePete O'Hanlon4-Apr-17 4:14 
GeneralRe: in which scenario people use factory design patter Pin
Gerry Schmitz4-Apr-17 4:36
mveGerry Schmitz4-Apr-17 4:36 
GeneralRe: in which scenario people use factory design patter Pin
Eddy Vluggen4-Apr-17 5:24
professionalEddy Vluggen4-Apr-17 5:24 
QuestionStrange Problem Loading Config File Pin
Kevin Marois3-Apr-17 7:51
professionalKevin Marois3-Apr-17 7:51 
AnswerRe: Strange Problem Loading Config File Pin
Richard Deeming3-Apr-17 8:03
mveRichard Deeming3-Apr-17 8:03 
GeneralRe: Strange Problem Loading Config File Pin
Kevin Marois3-Apr-17 8:07
professionalKevin Marois3-Apr-17 8:07 
QuestionUnderstanding IOC Pin
Liagapi2-Apr-17 21:06
Liagapi2-Apr-17 21:06 
AnswerRe: Understanding IOC Pin
Pete O'Hanlon2-Apr-17 22:41
mvePete O'Hanlon2-Apr-17 22:41 
GeneralRe: Understanding IOC Pin
Liagapi3-Apr-17 16:32
Liagapi3-Apr-17 16:32 
GeneralRe: Understanding IOC Pin
Pete O'Hanlon3-Apr-17 20:41
mvePete O'Hanlon3-Apr-17 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.