Example #1
0
        public void CloudFileDirectoryCreateIfNotExistsAPM()
        {
            CloudFileShare share = GetRandomShareReference();

            share.Create();

            try
            {
                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference("directory1");
                    IAsyncResult       result    = directory.BeginCreateIfNotExists(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    Assert.IsTrue(directory.EndCreateIfNotExists(result));
                    result = directory.BeginCreateIfNotExists(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    Assert.IsFalse(directory.EndCreateIfNotExists(result));
                    result = directory.BeginDelete(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    directory.EndDelete(result);
                    result = directory.BeginCreateIfNotExists(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    Assert.IsTrue(directory.EndCreateIfNotExists(result));
                }
            }
            finally
            {
                share.Delete();
            }
        }