Click here to Skip to main content
14,335,244 members
   

C#

 
AnswerRe: How do I apply the Settings.settings values at design time? Pin
OriginalGriff11-Apr-19 2:28
protectorOriginalGriff11-Apr-19 2:28 
GeneralRe: How do I apply the Settings.settings values at design time? Pin
Ayub Kokabi11-Apr-19 3:22
memberAyub Kokabi11-Apr-19 3:22 
Questionnon intersecting circles Pin
Member 1422403810-Apr-19 3:54
memberMember 1422403810-Apr-19 3:54 
AnswerRe: non intersecting circles Pin
OriginalGriff10-Apr-19 3:55
protectorOriginalGriff10-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
professionalLuc Pattyn10-Apr-19 9:58 
Questioncan't catch task exception with C# Pin
Member 142229339-Apr-19 16:08
memberMember 142229339-Apr-19 16:08 
I defined a CrawlerTimeoutException that is inherited from task exception, when I throw it in my code,I can't catch it in the main thread, the code is below:
try
            {
                Random rand = new Random();
                await Task.Delay(rand.Next(300, 1000));     //sims clicks
                var webcontent = await task.Crawl().Timeout(timeout);
            }
            catch (CrawlerTimeoutException)
            {
               //do something
               
            }
            catch (Exception exp)
            {
               //do something
            }

I threw the
CrawlerTimeoutException
in function
task.Crawl().Timeout(timeout);

the code is below:
public static Task<T> Timeout<T>(this Task<T> task, int millisecondsTimeout)
        {
            return Task.Factory.StartNew(() =>
            {
                bool succ = task.Wait(millisecondsTimeout);
                if (succ)
                    return task.Result;
                else
                    throw new CrawlerTimeoutException("Task timeout");//here is the error
            });
        }

when it times out, it will throw a exception, but the program will crash because it says: there is a exception that user-unhandled.
I don't know the reason, because I catch it in the main thread twice, but still don't catch it.
if you know the reason, please tell me!
thanks so much!

modified 10-Apr-19 0:04am.

AnswerRe: can't catch task exception with C# Pin
Member 142229339-Apr-19 18:07
memberMember 142229339-Apr-19 18:07 
AnswerRe: can't catch task exception with C# Pin
OriginalGriff9-Apr-19 20:05
protectorOriginalGriff9-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 
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
memberV 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
protectorMaciej 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
memberMou_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
mveEddy Vluggen10-Apr-19 0:21 
QuestionHow to equi join and left join between 3 List<t> Pin
Mou_kol9-Apr-19 9:41
memberMou_kol9-Apr-19 9:41 
QuestionApplication Server and Connection Method Pin
mikiz8-Apr-19 21:30
membermikiz8-Apr-19 21:30 
AnswerRe: Application Server and Connection Method Pin
Pete O'Hanlon9-Apr-19 1:22
protectorPete O'Hanlon9-Apr-19 1:22 
AnswerRe: Application Server and Connection Method Pin
Eddy Vluggen9-Apr-19 1:53
mveEddy Vluggen9-Apr-19 1:53 
GeneralRe: Application Server and Connection Method Pin
mikiz9-Apr-19 4:13
membermikiz9-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
mveEddy Vluggen9-Apr-19 5:48 
AnswerRe: Application Server and Connection Method Pin
Dave Kreskowiak9-Apr-19 3:05
mveDave Kreskowiak9-Apr-19 3:05 

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.