Click here to Skip to main content
15,881,559 members
Home / Discussions / C#
   

C#

 
AnswerRe: non intersecting circles Pin
OriginalGriff10-Apr-19 3:55
mveOriginalGriff10-Apr-19 3:55 
AnswerRe: non intersecting circles Pin
Dave Kreskowiak10-Apr-19 5:16
mveDave Kreskowiak10-Apr-19 5:16 
AnswerRe: non intersecting circles Pin
Gerry Schmitz10-Apr-19 6:46
mveGerry Schmitz10-Apr-19 6:46 
AnswerRe: non intersecting circles Pin
Luc Pattyn10-Apr-19 9:58
sitebuilderLuc Pattyn10-Apr-19 9:58 
Questioncan't catch task exception with C# Pin
Member 142229339-Apr-19 16:08
Member 142229339-Apr-19 16:08 
AnswerRe: can't catch task exception with C# Pin
Member 142229339-Apr-19 18:07
Member 142229339-Apr-19 18:07 
AnswerRe: can't catch task exception with C# Pin
OriginalGriff9-Apr-19 20:05
mveOriginalGriff9-Apr-19 20:05 
AnswerRe: can't catch task exception with C# Pin
Nathan Minier10-Apr-19 2:13
professionalNathan Minier10-Apr-19 2:13 
Yeah, exceptions thrown in an asynchronous context do not trigger exceptions in a synchronous one (I mean, how could it?)

So, first off, the "built-in" mechanism to do what you're trying to do here is to define a CancellationTokenSource with a timeout and pass that token to your task. You don't need to reinvent the wheel here.

Secondly, there are 2 contexts that you need to consider when handling exceptions in tasks. The first is a try-catch block as part of the task itself for block-level handling, and the second is an external handler for logging or any appropriate module-level responses. The block-level is the basic try-catch we know and love; the external looks sort of like this:
C#
class Program 
{
   static void Main(string[] args)
   {
      Task.Run(() =>{throw new NotImplementedException();})
         .ContinueWith(task => {
            if(task.IsFaulted) // Exception thrown in async task
            {
               Console.WriteLine($"Exception thrown: {task.Exception?.Message}");
            }
            else
            {
               Console.WriteLine("You shouldn't see this"));
            }
         });

      var k = Console.ReadLine(); //leave console open till enter is hit
   }
}
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor

AnswerRe: can't catch task exception with C# Pin
Richard Deeming15-Apr-19 8:11
mveRichard Deeming15-Apr-19 8:11 
QuestionCompare Two Complex List of data Pin
V Krishna9-Apr-19 16:07
V Krishna9-Apr-19 16:07 
AnswerRe: Compare Two Complex List of data Pin
Gerry Schmitz10-Apr-19 6:55
mveGerry Schmitz10-Apr-19 6:55 
QuestionRe: Compare Two Complex List of data Pin
Maciej Los10-Apr-19 10:27
mveMaciej Los10-Apr-19 10:27 
QuestionHow to update my list1 property value by list2 property value by joining Pin
Mou_kol9-Apr-19 9:42
Mou_kol9-Apr-19 9:42 
AnswerRe: How to update my list1 property value by list2 property value by joining Pin
Eddy Vluggen10-Apr-19 0:21
professionalEddy Vluggen10-Apr-19 0:21 
QuestionHow to equi join and left join between 3 List<t> Pin
Mou_kol9-Apr-19 9:41
Mou_kol9-Apr-19 9:41 
QuestionApplication Server and Connection Method Pin
mikiz8-Apr-19 21:30
mikiz8-Apr-19 21:30 
AnswerRe: Application Server and Connection Method Pin
Pete O'Hanlon9-Apr-19 1:22
mvePete O'Hanlon9-Apr-19 1:22 
AnswerRe: Application Server and Connection Method Pin
Eddy Vluggen9-Apr-19 1:53
professionalEddy Vluggen9-Apr-19 1:53 
GeneralRe: Application Server and Connection Method Pin
mikiz9-Apr-19 4:13
mikiz9-Apr-19 4:13 
GeneralRe: Application Server and Connection Method Pin
Dave Kreskowiak9-Apr-19 4:36
mveDave Kreskowiak9-Apr-19 4:36 
GeneralRe: Application Server and Connection Method Pin
Eddy Vluggen9-Apr-19 5:48
professionalEddy Vluggen9-Apr-19 5:48 
AnswerRe: Application Server and Connection Method Pin
Dave Kreskowiak9-Apr-19 3:05
mveDave Kreskowiak9-Apr-19 3:05 
GeneralRe: Application Server and Connection Method Pin
mikiz9-Apr-19 4:02
mikiz9-Apr-19 4:02 
GeneralRe: Application Server and Connection Method Pin
Eddy Vluggen9-Apr-19 8:56
professionalEddy Vluggen9-Apr-19 8:56 
GeneralRe: Application Server and Connection Method Pin
Dave Kreskowiak9-Apr-19 9:22
mveDave Kreskowiak9-Apr-19 9:22 

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.