public static void AsyncUsing(Action action, bool useSymbiosis) { Task.Run(() => { try { Initialize(); if (useSymbiosis) { Symbiosis.Open(); } action(); } catch (Exception ex) { LogWrapper.Default.Fatal(ex); } finally { if (useSymbiosis) { Symbiosis.Close(); } Dispose(); } }); }
/// <summary> /// 关闭当前共生器 /// </summary> public static void Close() { Symbiosis sym = Current; sym.OpenTimes--; if (sym.OpenTimes == 0) { _pool.Return(sym); Current = null; } }
/// <summary> /// 打开共生器 /// </summary> public static Symbiosis Open() { Symbiosis sym; if (ExistsCurrent()) { sym = Current; } else { sym = _pool.Borrow(); Current = sym; } sym.OpenTimes++; return(sym); }
/// <summary> /// /// </summary> public static void Using(Action action, bool useSymbiosis) { try { Initialize(); if (useSymbiosis) { Symbiosis.Open(); } action(); } catch (Exception ex) { throw ex; } finally { if (useSymbiosis) { Symbiosis.Close(); } Dispose(); } }