Ejemplo n.º 1
0
 internal static void Shutdown()
 {
     if (Runtime.Py_IsInitialized() == 0)
     {
         Instance._objQueue = new ConcurrentQueue <IPyDisposable>();
         return;
     }
     Instance.DisposeAll();
     if (Thread.CurrentThread.ManagedThreadId != Runtime.MainManagedThreadId)
     {
         if (Instance._pendingArgs == IntPtr.Zero)
         {
             Instance.ResetPending();
             return;
         }
         // Not in main thread just cancel the pending operation to avoid error in different domain
         // It will make a memory leak
         unsafe
         {
             PendingArgs *args = (PendingArgs *)Instance._pendingArgs;
             args->cancelled = true;
         }
         Instance.ResetPending();
         return;
     }
     Instance.CallPendingFinalizers();
 }
Ejemplo n.º 2
0
 private static int OnPendingCollect(IntPtr arg)
 {
     Debug.Assert(arg == Instance._pendingArgs);
     try
     {
         unsafe
         {
             PendingArgs *pendingArgs = (PendingArgs *)arg;
             if (pendingArgs->cancelled)
             {
                 return(0);
             }
         }
         Instance.DisposeAll();
     }
     finally
     {
         Instance.FreePendingArgs();
         Instance.ResetPending();
     }
     return(0);
 }