public static void TryWaitOnHandleAndDispose(ref System.Threading.WaitHandle handle)
        {
            if (object.ReferenceEquals(handle, NilWaitHandle))
            {
                return;
            }

            try
            {
                handle.WaitOne();
            }
            catch (System.ObjectDisposedException)
            {
                return;
            }
            catch (System.Exception ex)
            {
                //Should just return? (At least document that it will throw and how to catch or ignore)
                TaggedExceptionExtensions.TryRaiseTaggedException(handle, "An exception occured while waiting.", ex);
            }
            finally
            {
                if (object.ReferenceEquals(handle, NilWaitHandle).Equals(false))
                {
                    handle.Dispose();
                }
            }

            handle = null;
        }
示例#2
0
        public static bool TryWebClientDownload(System.Uri location, out System.IO.Stream result, System.Net.NetworkCredential credential = null)
        {
            result = null;

            try
            {
                result = WebClientDownload(location, credential);

                return(result != null);
            }
            catch (System.Exception ex)
            {
                TaggedExceptionExtensions.TryRaiseTaggedException(result, ex.Message, ex);

                return(false);
            }
        }