Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SafeAction.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Runtime.CompilerServices;
5 using System.Threading;
6 
7 namespace SiliconStudio.Core.Diagnostics
8 {
9  public static class SafeAction
10  {
11  private static readonly Logger Log = GlobalLogger.GetLogger("SafeAction");
12 
13  public static ThreadStart Wrap(ThreadStart action, [CallerFilePath] string sourceFilePath = "", [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0)
14  {
15  return () =>
16  {
17  try
18  {
19  action();
20  }
21  catch (ThreadAbortException)
22  {
23  // Ignore this exception
24  }
25  catch (Exception e)
26  {
27  Log.Fatal("Unexpected exception", e, CallerInfo.Get(sourceFilePath, memberName, sourceLineNumber));
28  throw;
29  }
30  };
31  }
32 
33  public static ParameterizedThreadStart Wrap(ParameterizedThreadStart action, [CallerFilePath] string sourceFilePath = "", [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0)
34  {
35  return obj =>
36  {
37  try
38  {
39  action(obj);
40  }
41  catch (ThreadAbortException)
42  {
43  // Ignore this exception
44  }
45  catch (Exception e)
46  {
47  Log.Fatal("Unexpected exception", e, CallerInfo.Get(sourceFilePath, memberName, sourceLineNumber));
48  throw;
49  }
50  };
51  }
52  }
53 }
static ThreadStart Wrap(ThreadStart action, [CallerFilePath] string sourceFilePath="", [CallerMemberName] string memberName="", [CallerLineNumber] int sourceLineNumber=0)
Definition: SafeAction.cs:13
Base implementation for ILogger.
Definition: Logger.cs:10
static ParameterizedThreadStart Wrap(ParameterizedThreadStart action, [CallerFilePath] string sourceFilePath="", [CallerMemberName] string memberName="", [CallerLineNumber] int sourceLineNumber=0)
Definition: SafeAction.cs:33
Output message to log right away.