Exemplo n.º 1
0
        /// <summary>
        /// Requests a registered object to unregister on app domain unload in a web project
        /// </summary>
        /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
        public void Stop(bool immediate)
        {
            if (immediate)
            {
                //This is sort of a hack at the moment. We are disposing the searchers at the last possible point in time because there might
                // still be pages executing when 'immediate' == false. In which case, when we close the readers, exceptions will occur
                // if the search results are still being enumerated.
                // I've tried using DecRef and IncRef to keep track of searchers using readers, however there is no guarantee that DecRef can
                // be called when a search is finished and since search results are lazy, we don't know when they end unless people dispose them
                // or always use a foreach loop which can't really be forced. The only alternative to using DecRef and IncRef would be to make the results
                // not lazy which isn't good.

                foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
                {
                    searcher.Dispose();
                }

                OpenReaderTracker.Current.CloseAllReaders();

                HostingEnvironment.UnregisterObject(this);
            }
            else
            {
                foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
                {
                    indexer.Dispose();
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Requests a registered object to unregister on app domain unload in a web project
 /// </summary>
 /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
 public void Stop(bool immediate)
 {
     foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
     {
         searcher.Dispose();
     }
     foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
     {
         indexer.Dispose();
     }
 }