예제 #1
0
        public void Cancel_CanBeSuppressed(AsyncCreationOptions options, bool expectedCompleted)
        {
            // Arrange
            var op = new AsyncCompletionSource(options);

            // Act
            op.Cancel();

            // Assert
            Assert.Equal(expectedCompleted, op.IsCompleted);
        }
        public async Task AddCompletionCallback_IsThreadSafe(AsyncCreationOptions creationOptions)
        {
            // Arrange
            var op      = new AsyncCompletionSource(creationOptions);
            var counter = 0;
            var d       = new Action <IAsyncOperation>(CompletionCallback);

            void CompletionCallback(IAsyncOperation o)
            {
                Interlocked.Increment(ref counter);
            }

            void TestMethod()
            {
                for (var i = 0; i < 10000; ++i)
                {
                    op.AddCompletionCallback(d);
                }
            }

            void TestMethod2()
            {
                for (var i = 0; i < 10000; ++i)
                {
                    op.RemoveCallback(d);
                }
            }

            TestMethod();

            // Act
            await Task.WhenAll(
                Task.Run(new Action(TestMethod)),
                Task.Run(new Action(TestMethod)),
                Task.Run(new Action(TestMethod2)),
                Task.Run(new Action(TestMethod)));

            // Assert
            op.SetCompleted();
            Assert.Equal(30000, counter);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult"/> class with the specified <see cref="CreationOptions"/>.
 /// </summary>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncCreationOptions options)
     : this((int)options << _optionsOffset)
 {
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult"/> class with the specified <see cref="Status"/> and <see cref="CreationOptions"/>.
 /// </summary>
 /// <param name="status">Initial value of the <see cref="Status"/> property.</param>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data returned by <see cref="AsyncState"/>.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncOperationStatus status, AsyncCallback asyncCallback, object asyncState, AsyncCreationOptions options)
     : this((int)status | ((int)options << _optionsOffset))
 {
     _asyncState = asyncState;
     _callback   = asyncCallback;
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult"/> class with the specified <see cref="Status"/> and <see cref="CreationOptions"/>.
 /// </summary>
 /// <param name="status">Initial value of the <see cref="Status"/> property.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options)
     : this((int)status | ((int)options << _optionsOffset))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="status">Initial value of the <see cref="AsyncResult.Status"/> property.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncCompletionSource(AsyncOperationStatus status, AsyncCreationOptions options)
     : base(status, options)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncCompletionSource(AsyncCallback asyncCallback, object asyncState, AsyncCreationOptions options)
     : base(asyncCallback, asyncState, options)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncCompletionSource(object asyncState, AsyncCreationOptions options)
     : base(default(AsyncCallback), asyncState, options)
 {
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="status">Status value of the operation.</param>
 /// <param name="asyncState">User-defined data to assosiate with the operation.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncOperationStatus status, object asyncState, AsyncCreationOptions options)
     : base(status, asyncState, options)
 {
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 /// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
 public AsyncCompletionSource(AsyncCreationOptions options, object asyncState)
     : base(options, null, asyncState)
 {
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="status">Initial value of the <see cref="AsyncResult.Status"/> property.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
 public AsyncCompletionSource(AsyncOperationStatus status, AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
     : base(status, options, asyncCallback, asyncState)
 {
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data to assosiate with the operation.</param>
 public AsyncResult(AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
     : base(options, asyncCallback, asyncState)
 {
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncCreationOptions options)
     : base(options)
 {
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="status">Status value of the operation.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data to assosiate with the operation.</param>
 public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
     : base(status, options, asyncCallback, asyncState)
 {
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="status">Status value of the operation.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options)
     : base(status, options)
 {
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncResult{T}"/> class.
 /// </summary>
 /// <param name="asyncCallback">User-defined completion callback.</param>
 /// <param name="asyncState">User-defined data to assosiate with the operation.</param>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncResult(AsyncCallback asyncCallback, object asyncState, AsyncCreationOptions options)
     : base(asyncCallback, asyncState, options)
 {
 }
예제 #17
0
        public void Constructor_SetsCorrectStatusAndOptions(AsyncOperationStatus status, AsyncCreationOptions options)
        {
            // Arrange/Act
            var op  = new AsyncResult(status, options);
            var op2 = new AsyncResult(status, options, null);
            var op3 = new AsyncResult(status, options, null, null);

            // Assert
            Assert.Equal(status, op.Status);
            Assert.Equal(options, op.CreationOptions);
            Assert.Equal(status, op2.Status);
            Assert.Equal(options, op2.CreationOptions);
            Assert.Equal(status, op3.Status);
            Assert.Equal(options, op3.CreationOptions);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncCompletionSource{T}"/> class.
 /// </summary>
 /// <param name="options">The <see cref="AsyncCreationOptions"/> used to customize the operation's behavior.</param>
 public AsyncCompletionSource(AsyncCreationOptions options)
     : base(options)
 {
 }