Example #1
0
        /// <summary>
        /// Ends the open container process.
        /// </summary>
        /// <returns>The open StorageContainer.</returns>
        /// <param name="result">Result of BeginOpenContainer.</param>
        public StorageContainer EndOpenContainer(IAsyncResult result)
        {
            StorageContainer returnValue = null;

            try
            {
                // Retrieve the delegate.
                AsyncResult asyncResult = result as AsyncResult;
                if (asyncResult != null)
                {
                    OpenContainerAsynchronous asyncDelegate = asyncResult.AsyncDelegate
                                                              as OpenContainerAsynchronous;

                    // Wait for the WaitHandle to become signaled.
                    result.AsyncWaitHandle.WaitOne();

                    // Call EndInvoke to retrieve the results.
                    if (asyncDelegate != null)
                    {
                        returnValue = asyncDelegate.EndInvoke(result);
                    }
                }
            }
            finally
            {
                // Close the wait handle.
                result.AsyncWaitHandle.Dispose();
            }

            return(returnValue);
        }
 private IAsyncResult OpenContainer(string displayName, AsyncCallback callback, object state)
 {
     try {
         OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
         return(AsynchronousOpen.BeginInvoke(displayName, callback, state));
     } finally {
     }
 }
Example #3
0
 /// <summary>
 /// Begins the open for a StorageContainer.
 /// </summary>
 /// <returns>The open StorageContainer.</returns>
 /// <param name="displayName">Name of file.</param>
 /// <param name="callback">Method to call on completion.</param>
 /// <param name="state">Request identifier object for callback (can be null).</param>
 public IAsyncResult BeginOpenContainer(
     string displayName,
     AsyncCallback callback,
     object state
     )
 {
     try
     {
         OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
         return(AsynchronousOpen.BeginInvoke(displayName, callback, state));
     }
     finally
     {
         // TODO:  No resources to clean up?  Remove this finally block?
     }
 }
Example #4
0
        public StorageContainer EndOpenContainer(IAsyncResult result)
        {
            StorageContainer storageContainer = (StorageContainer)null;

            try
            {
                OpenContainerAsynchronous containerAsynchronous = result.AsyncState as OpenContainerAsynchronous;
                result.AsyncWaitHandle.WaitOne();
                if (containerAsynchronous != null)
                {
                    storageContainer = containerAsynchronous.EndInvoke(result);
                }
            }
            finally
            {
                result.AsyncWaitHandle.Dispose();
            }
            return(storageContainer);
        }
Example #5
0
        private IAsyncResult OpenContainer(string displayName, AsyncCallback callback, object state)
        {
#if !WINDOWS_PHONE81 && !ANDROID && !IOS && !NETFX_CORE && !WINDOWS_PHONE
            try
            {
                OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
#if WINRT
                containerDelegate = AsynchronousOpen;
#endif
                return(AsynchronousOpen.BeginInvoke(displayName, callback, state));
            }
            finally
            {
            }
#else
            var tcs  = new TaskCompletionSource <StorageContainer>(state);
            var task = Task.Run <StorageContainer>(() => Open(displayName));
            task.ContinueWith(t =>
            {
                // Copy the task result into the returned task.
                if (t.IsFaulted)
                {
                    tcs.TrySetException(t.Exception.InnerExceptions);
                }
                else if (t.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(t.Result);
                }

                // Invoke the user callback if necessary.
                if (callback != null)
                {
                    callback(tcs.Task);
                }
            });
            return(tcs.Task);
#endif
        }
Example #6
0
		private IAsyncResult OpenContainer (string displayName, AsyncCallback callback, object state)
		{
			try {
				OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous (Open);
#if WINRT
                containerDelegate = AsynchronousOpen;
#endif
                return AsynchronousOpen.BeginInvoke (displayName, callback, state);
			} finally {
			}
		}
Example #7
0
		/// <summary>
		/// Begins the open for a StorageContainer.
		/// </summary>
		/// <returns>The open StorageContainer.</returns>
		/// <param name="displayName">Name of file.</param>
		/// <param name="callback">Method to call on completion.</param>
		/// <param name="state">Request identifier object for callback (can be null).</param>
		public IAsyncResult BeginOpenContainer(
			string displayName,
			AsyncCallback callback,
			object state
		) {
			try
			{
				OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
				return AsynchronousOpen.BeginInvoke(displayName, callback, state);
			}
			finally
			{
				// TODO:  No resources to clean up?  Remove this finally block?
			}
		}
Example #8
0
		private IAsyncResult OpenContainer (string displayName, AsyncCallback callback, object state)
        {

#if !WINDOWS_PHONE81 && !ANDROID && !IOS && !NETFX_CORE && !WINDOWS_PHONE
            try
            {
                OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
#if WINRT
                containerDelegate = AsynchronousOpen;
#endif
                return AsynchronousOpen.BeginInvoke(displayName, callback, state);
            }
            finally
            {
            }
#else
            var tcs = new TaskCompletionSource<StorageContainer>(state);
            var task = Task.Run<StorageContainer>(() => Open(displayName));
            task.ContinueWith(t =>
            {
                // Copy the task result into the returned task.
                if (t.IsFaulted)
                    tcs.TrySetException(t.Exception.InnerExceptions);
                else if (t.IsCanceled)
                    tcs.TrySetCanceled();
                else
                    tcs.TrySetResult(t.Result);

                // Invoke the user callback if necessary.
                if (callback != null)
                    callback(tcs.Task);
            });
            return tcs.Task;
#endif
        }