c# - An unhandled exception breaks the application? -


it said in .net 4.0, unhandled exception in task make application broken when finalized. (it said in .net 4.5, ms edits exception rule unhandled exception won't thrown).

but tried below code, see appliction. (in .net4.0), seems strong.

static void main(string[] args) {      (int = 0; < 100; i++)     {         var t = task.factory.startnew<int>(() => { throw new exception("xxxxxx"); return 1; }             , cancellationtoken.none, taskcreationoptions.none, taskscheduler.default);     }      while (true)     {         gc.collect();         thread.sleep(1000);     }     console.readkey(); } 

the code run gc.collect() finalize task object, application ok. isn't broken.

why?

if have .net 4.5 installed on machine, in place modification of .net 4.0 may why getting behavior seeing.

if want unobserved exceptions still thrown can add following section config file:

<configuration>     <runtime>       <throwunobservedtaskexceptions enabled="true"/>     </runtime> </configuration> 

more info <throwunobservedtaskexceptions>.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -