Preventing crashes using UnhandledExceptionHandlerWindsor IoC Sample Help - “HttpServiceWatcher& which was not registered.”iPhone - Crash on a secondary thread doesn't affect main threaddealloc called on same thread as running method causes crash by race condition, is that expected?Referencing an object (class) within a thread failsWhy does FileSystemWatcher fire twiceVB Net Update GUI from Thread in a different vb fileDataGridViewRowsAdded handler gives errorsWinforms app does not shut downHow to catch all unhandled exceptions in WinForms application correctlyUIApplication OpenURL crash with 0x000000008badf00d

What is the term for a person whose job is to place products on shelves in stores?

What to do with someone that cheated their way through university and a PhD program?

Complex numbers z=-3-4i polar form

How to pronounce 'c++' in Spanish

Is there metaphorical meaning of "aus der Haft entlassen"?

Why did C use the -> operator instead of reusing the . operator?

Is it acceptable to use working hours to read general interest books?

Find the identical rows in a matrix

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

What makes accurate emulation of old systems a difficult task?

Mistake in years of experience in resume?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Does the damage from the Absorb Elements spell apply to your next attack, or to your first attack on your next turn?

Unknown code in script

Should the Product Owner dictate what info the UI needs to display?

Is there a word for the censored part of a video?

Double-nominative constructions and “von”

What's the difference between using dependency injection with a container and using a service locator?

What does a straight horizontal line above a few notes, after a changed tempo mean?

Find a stone which is not the lightest one

Prove that the countable union of countable sets is also countable

Can a stored procedure reference the database in which it is stored?

Why is the underscore command _ useful?



Preventing crashes using UnhandledExceptionHandler


Windsor IoC Sample Help - “HttpServiceWatcher& which was not registered.”iPhone - Crash on a secondary thread doesn't affect main threaddealloc called on same thread as running method causes crash by race condition, is that expected?Referencing an object (class) within a thread failsWhy does FileSystemWatcher fire twiceVB Net Update GUI from Thread in a different vb fileDataGridViewRowsAdded handler gives errorsWinforms app does not shut downHow to catch all unhandled exceptions in WinForms application correctlyUIApplication OpenURL crash with 0x000000008badf00d






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Preface: I'm perfectly aware of how bad doing this is, I'm just curious as to why it works



I saw this piece of code while browsing questions related to UnhandledException and wondered why calling Thread.CurrentThread.Join() in the handler prevents the app from crashing, and what does a thread calling Join() on itself even mean in this scenario?



AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException


Public Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Console.WriteLine($"[ERROR] DirectCast(e.ExceptionObject, Exception).Message")
'Thread.CurrentThread.IsBackground = True
Thread.CurrentThread.Join()
End Sub


I also noticed that that while this handler does indeed prevent crashing the app it seems to leave threads in some unknown/running state (I mean, everything is in an undefined state at this point anyway; but still) which means uncommenting the Thread.CurrentThread.IsBackground = True allows the app to exit when the main thread finishes.



Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException

Application.Run(New Form1) ' Form1 has a button that starts a thread which throws an exception
' This is only reached when Form1 is closed, but if there is
' no Thread.CurrentThread.IsBackground = True the app keeps running
' in the background because the other threads are still running or in
' an alive-ish state
End Sub


tl;dr: Why does calling Thread.CurrentThread.Join() in the UnhandledExceptionHandler prevent an app from crashing?










share|improve this question
























  • The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

    – jmcilhinney
    Mar 9 at 7:46











  • @jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

    – John Mark Gabriel Caguicla
    Mar 9 at 8:15


















0















Preface: I'm perfectly aware of how bad doing this is, I'm just curious as to why it works



I saw this piece of code while browsing questions related to UnhandledException and wondered why calling Thread.CurrentThread.Join() in the handler prevents the app from crashing, and what does a thread calling Join() on itself even mean in this scenario?



AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException


Public Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Console.WriteLine($"[ERROR] DirectCast(e.ExceptionObject, Exception).Message")
'Thread.CurrentThread.IsBackground = True
Thread.CurrentThread.Join()
End Sub


I also noticed that that while this handler does indeed prevent crashing the app it seems to leave threads in some unknown/running state (I mean, everything is in an undefined state at this point anyway; but still) which means uncommenting the Thread.CurrentThread.IsBackground = True allows the app to exit when the main thread finishes.



Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException

Application.Run(New Form1) ' Form1 has a button that starts a thread which throws an exception
' This is only reached when Form1 is closed, but if there is
' no Thread.CurrentThread.IsBackground = True the app keeps running
' in the background because the other threads are still running or in
' an alive-ish state
End Sub


tl;dr: Why does calling Thread.CurrentThread.Join() in the UnhandledExceptionHandler prevent an app from crashing?










share|improve this question
























  • The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

    – jmcilhinney
    Mar 9 at 7:46











  • @jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

    – John Mark Gabriel Caguicla
    Mar 9 at 8:15














0












0








0








Preface: I'm perfectly aware of how bad doing this is, I'm just curious as to why it works



I saw this piece of code while browsing questions related to UnhandledException and wondered why calling Thread.CurrentThread.Join() in the handler prevents the app from crashing, and what does a thread calling Join() on itself even mean in this scenario?



AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException


Public Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Console.WriteLine($"[ERROR] DirectCast(e.ExceptionObject, Exception).Message")
'Thread.CurrentThread.IsBackground = True
Thread.CurrentThread.Join()
End Sub


I also noticed that that while this handler does indeed prevent crashing the app it seems to leave threads in some unknown/running state (I mean, everything is in an undefined state at this point anyway; but still) which means uncommenting the Thread.CurrentThread.IsBackground = True allows the app to exit when the main thread finishes.



Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException

Application.Run(New Form1) ' Form1 has a button that starts a thread which throws an exception
' This is only reached when Form1 is closed, but if there is
' no Thread.CurrentThread.IsBackground = True the app keeps running
' in the background because the other threads are still running or in
' an alive-ish state
End Sub


tl;dr: Why does calling Thread.CurrentThread.Join() in the UnhandledExceptionHandler prevent an app from crashing?










share|improve this question
















Preface: I'm perfectly aware of how bad doing this is, I'm just curious as to why it works



I saw this piece of code while browsing questions related to UnhandledException and wondered why calling Thread.CurrentThread.Join() in the handler prevents the app from crashing, and what does a thread calling Join() on itself even mean in this scenario?



AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException


Public Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Console.WriteLine($"[ERROR] DirectCast(e.ExceptionObject, Exception).Message")
'Thread.CurrentThread.IsBackground = True
Thread.CurrentThread.Join()
End Sub


I also noticed that that while this handler does indeed prevent crashing the app it seems to leave threads in some unknown/running state (I mean, everything is in an undefined state at this point anyway; but still) which means uncommenting the Thread.CurrentThread.IsBackground = True allows the app to exit when the main thread finishes.



Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException

Application.Run(New Form1) ' Form1 has a button that starts a thread which throws an exception
' This is only reached when Form1 is closed, but if there is
' no Thread.CurrentThread.IsBackground = True the app keeps running
' in the background because the other threads are still running or in
' an alive-ish state
End Sub


tl;dr: Why does calling Thread.CurrentThread.Join() in the UnhandledExceptionHandler prevent an app from crashing?







.net vb.net multithreading unhandled-exception






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 7:41







John Mark Gabriel Caguicla

















asked Mar 9 at 7:32









John Mark Gabriel CaguiclaJohn Mark Gabriel Caguicla

144




144












  • The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

    – jmcilhinney
    Mar 9 at 7:46











  • @jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

    – John Mark Gabriel Caguicla
    Mar 9 at 8:15


















  • The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

    – jmcilhinney
    Mar 9 at 7:46











  • @jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

    – John Mark Gabriel Caguicla
    Mar 9 at 8:15

















The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

– jmcilhinney
Mar 9 at 7:46





The documentation explicitly states that you should not call Join on the current thread because it will prevent the thread terminating, so that is obviously the intention here. The thread on which the exception was thrown will never terminate of its own accord but, because it is a background thread, will not stop the application quitting. That all looks rather dodgy to me. Given that the application framework provides an UnhandledException event that allows you to prevent the application closing, I wonder whether it does that same thing.

– jmcilhinney
Mar 9 at 7:46













@jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

– John Mark Gabriel Caguicla
Mar 9 at 8:15






@jmcilhinney Ah that makes sense, the self-Join essentially prevents the thread from exiting the handler and reaching .NET's actual Unhandled Exception handler (which presumably terminates the app) by causing the thread to hang.

– John Mark Gabriel Caguicla
Mar 9 at 8:15













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075074%2fpreventing-crashes-using-unhandledexceptionhandler%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075074%2fpreventing-crashes-using-unhandledexceptionhandler%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко