How to check if Thread code works in try-catch block

I would like to check our code and see if every executable thread in the try catch block works.

Valid Sample:

Thread loadDataThread = new Thread(new ThreadStart(LoadData));
public void LoadData()
{
   try {/*do something*/}
   catch(Exception ex) { /*Handle exception*/ }
}

Invalid sample:

Thread loadDataThread = new Thread(new ThreadStart(LoadData));
public void LoadData()
{
   /* do something */
}

This is something that can be checked with FxCop or another tool. A similar rule can be applied to some other things, for example. Timer Ticks etc.

+3
source share
4 answers

. http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/a257a910-126e-4c8d-aab3-3199347346ec , try/catch wrapping FxCop. , , , , Thread.Start ThreadPool.QueueUserWorkItem.

, , / , , try/catch. ( FxCop, , /.) , (: , ..) , .

+1

, FXCop, Mono.Cecil , .

0

- FxCop. Google.

, Thread. , . ref , , .

0

, , , .

, , , , ? , app.config :

<runtime>
<legacyUnhandledExceptionPolicy enabled="1"/>
</runtime>

, .

. , - , . , , ,

    void AppStartup()
    {
        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    }

    void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        //log error            
    }
0

Source: https://habr.com/ru/post/1764670/


All Articles