/// <summary>
 /// Gets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <returns>the selection or <c>null</c></returns>
 internal static Object GetSelection(XSelectionSupplier selectProv)
 {
     if (selectProv != null)
     {
         var selection = selectProv.getSelection().Value;
         return(selection);
     }
     return(null);
 }
        //static readonly Object _selectionLock = new Object();
        /// <summary>
        /// Get the current selection.
        /// </summary>
        /// <param name="selectionSupplier">The selection supplier.</param>
        /// <returns><c>false</c> if no selection could be achieved; otherwise and [XShapes] collection</returns>
        /// <remarks>This request is locked and time limited to 100 ms.</remarks>
        public static Object GetSelection(XSelectionSupplier selectionSupplier)
        {
            Object selection = false;

            if (selectionSupplier != null)
            {
                //FIXME: you cannot do this in a time limited execution this will lead to an hang on -- why??????
                try
                {
                    lock (selectionSupplier)
                    {
                        TimeLimitExecutor.WaitForExecuteWithTimeLimit(100, () =>
                        {
                            Thread.BeginCriticalRegion();
                            var anySelection = selectionSupplier.getSelection();
                            Thread.EndCriticalRegion();

                            if (anySelection.hasValue())
                            {
                                selection = anySelection.Value;
                            }
                            else
                            {
                                selection = null;
                            }
                        }, "GetSelection");
                    }
                }
                catch (DisposedException)
                {
                    Logger.Instance.Log(LogPriority.DEBUG, "OoSelectionObserver", "Selection supplier disposed");
                    OO.CheckConnection();
                }
                catch (ThreadAbortException) { }
                catch (ThreadInterruptedException) { }
            }
            return(selection);
        }
 /// <summary>
 /// Gets the selection.
 /// </summary>
 /// <param name="selectProv">The selection provider - commonly this is the document.</param>
 /// <returns>the selection or <c>null</c></returns>
 internal static Object GetSelection(XSelectionSupplier selectProv)
 {
     if (selectProv != null)
     {
         var selection = selectProv.getSelection().Value;
         return selection;
     }
     return null;
 }
 public static Object GetSelection(XSelectionSupplier selectionSupplier)
 {
     Object selection = null;
     if (selectionSupplier != null)
     {
         lock (_selectionLock)
         {
             //FIXME: you cannot do this in a time limited execution this will lead to an hang on -- why??????
             try
             {
                // TimeLimitExecutor.WaitForExecuteWithTimeLimit(20000, () =>
                 //{
                     Thread.BeginCriticalRegion();
                     var anySelection = selectionSupplier.getSelection();
                     Thread.EndCriticalRegion();
                 
                     if (anySelection.hasValue())
                     {
                         selection = anySelection.Value;
                     }
                 // }, "GetSelection");
             }
             catch (DisposedException)
             {
                 Logger.Instance.Log(LogPriority.DEBUG, "OoSelectionObserver", "Selection supplier disposed");
                 OO.CheckConnection();
             }
             catch (ThreadAbortException) { }
         }
     }
     return selection;
 }