mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-23 10:22:03 +08:00
配置文件功能完善
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Application
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
public static Task Forget(
|
||||
this Task task,
|
||||
[CallerMemberName] string callerMemberName = "",
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
return task.ContinueWith(
|
||||
x => TaskLog.Raise(new TaskLog(callerMemberName, callerFilePath, callerLineNumber, x.Exception)),
|
||||
TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
|
||||
public static void ForgetAndDispose(
|
||||
this Task task,
|
||||
[CallerMemberName] string callerMemberName = "",
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
task.ContinueWith(
|
||||
x => TaskLog.Raise(new TaskLog(callerMemberName, callerFilePath, callerLineNumber, x.Exception)),
|
||||
TaskContinuationOptions.OnlyOnFaulted).ContinueWith(s=>s.Dispose());
|
||||
}
|
||||
|
||||
public static Task WhenAll(this IEnumerable<Task> tasks)
|
||||
{
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public static Task<T[]> WhenAll<T>(this IEnumerable<Task<T>> tasks)
|
||||
{
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
}
|
||||
|
||||
public class TaskLog
|
||||
{
|
||||
public string CallerMemberName { get; }
|
||||
|
||||
public string CallerFilePath { get; }
|
||||
|
||||
public int CallerLineNumber { get; }
|
||||
|
||||
public Exception Exception { get; }
|
||||
|
||||
public TaskLog(string callerMemberName, string callerFilePath, int callerLineNumber, Exception exception)
|
||||
{
|
||||
this.CallerMemberName = callerMemberName;
|
||||
this.CallerFilePath = callerFilePath;
|
||||
this.CallerLineNumber = callerLineNumber;
|
||||
this.Exception = exception;
|
||||
}
|
||||
|
||||
|
||||
public static EventHandler<TaskLog> Occured = (sender, e) =>
|
||||
{
|
||||
const string format = @"Unhandled Exception occured from Task.Forget()
|
||||
-----------
|
||||
Caller file : {1}
|
||||
: line {2}
|
||||
Caller member: {0}
|
||||
Exception: {3}
|
||||
|
||||
";
|
||||
System.Diagnostics.Debug.WriteLine(format, e.CallerMemberName, e.CallerFilePath, e.CallerLineNumber, e.Exception);
|
||||
};
|
||||
|
||||
internal static void Raise(TaskLog log)
|
||||
{
|
||||
Occured?.Invoke(typeof(TaskLog), log);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user