예제 #1
0
 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();
         }
     });
 }
예제 #2
0
        /// <summary>
        /// 关闭当前共生器
        /// </summary>
        public static void Close()
        {
            Symbiosis sym = Current;

            sym.OpenTimes--;
            if (sym.OpenTimes == 0)
            {
                _pool.Return(sym);
                Current = null;
            }
        }
예제 #3
0
        /// <summary>
        /// 打开共生器
        /// </summary>
        public static Symbiosis Open()
        {
            Symbiosis sym;

            if (ExistsCurrent())
            {
                sym = Current;
            }
            else
            {
                sym     = _pool.Borrow();
                Current = sym;
            }
            sym.OpenTimes++;
            return(sym);
        }
예제 #4
0
 /// <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();
     }
 }