当前位置: 首页>>代码示例>>C#>>正文


C# Action.Invoke方法代码示例

本文整理汇总了C#中Action.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.Invoke方法的具体用法?C# Action.Invoke怎么用?C# Action.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Action的用法示例。


在下文中一共展示了Action.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: When

 private void When(Action when)
 {
     using (_mocks.Playback())
     {
         when.Invoke();
     }
 }
开发者ID:smhabdoli,项目名称:NBehave,代码行数:7,代码来源:StoryRunnerFilterSpecs.cs

示例2: Given

 private void Given(Action given)
 {
     using (_mocks.Record())
     {
         given.Invoke();
     }
 }
开发者ID:smhabdoli,项目名称:NBehave,代码行数:7,代码来源:StoryRunnerFilterSpecs.cs

示例3: WriteElementBlock

 public static void WriteElementBlock(this XmlWriter xmlWriter, string localName, string ns, Action<XmlWriter> action)
 {
     xmlWriter.WriteStartElement(localName, ns);
     action.Invoke(xmlWriter);
     xmlWriter.WriteEndElement();
     xmlWriter.Flush();
 }
开发者ID:Andrea,项目名称:nxmpp,代码行数:7,代码来源:XmlWriterExtensions.cs

示例4: Configure

        /// <summary>
        /// Performs configuration for <see cref="GlobalConfiguration.Configuration"/> and ensures that it is
        /// initialized.
        /// </summary>
        /// <param name="configurationCallback">The callback that will perform the configuration.</param>
        public static void Configure(Action<HttpConfiguration> configurationCallback)
        {
            if (configurationCallback == null)
            {
                throw new ArgumentNullException("configurationCallback");
            }

            configurationCallback.Invoke(Configuration);
            Configuration.EnsureInitialized();
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:GlobalConfiguration.cs

示例5: Then

 private void Then(Action then)
 {
     _mocks.ReplayAll();
     then.Invoke();
 }
开发者ID:smhabdoli,项目名称:NBehave,代码行数:5,代码来源:StoryRunnerFilterSpecs.cs

示例6: TestExceptionFilter

        private static void TestExceptionFilter(ApiController controller, Exception expectedException,
            Action<HttpConfiguration> configure)
        {
            // Arrange
            Exception actualException = null;
            IHttpRouteData routeData = new HttpRouteData(new HttpRoute());

            using (HttpRequestMessage request = new HttpRequestMessage())
            using (HttpConfiguration configuration = new HttpConfiguration())
            using (HttpResponseMessage response = new HttpResponseMessage())
            {
                HttpControllerContext context = new HttpControllerContext(configuration, routeData, request);
                HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(configuration,
                    "Ignored", controller.GetType());
                context.Controller = controller;
                context.ControllerDescriptor = controllerDescriptor;

                if (configure != null)
                {
                    configure.Invoke(configuration);
                }

                Mock<IExceptionFilter> spy = new Mock<IExceptionFilter>();
                spy.Setup(f => f.ExecuteExceptionFilterAsync(It.IsAny<HttpActionExecutedContext>(),
                    It.IsAny<CancellationToken>())).Returns<HttpActionExecutedContext, CancellationToken>(
                    (c, i) =>
                    {
                        actualException = c.Exception;
                        c.Response = response;
                        return Task.FromResult<object>(null);
                    });

                configuration.Filters.Add(spy.Object);

                // Act
                HttpResponseMessage ignore = controller.ExecuteAsync(context, CancellationToken.None).Result;
            }

            // Assert
            Assert.Same(expectedException, actualException);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:41,代码来源:ApiControllerTest.cs

示例7: CreateAuthenticationFilterChallenge

 private static IAuthenticationFilter CreateAuthenticationFilterChallenge(
     Action<HttpAuthenticationChallengeContext, CancellationToken> challenge)
 {
     Mock<IAuthenticationFilter> mock = new Mock<IAuthenticationFilter>();
     mock.Setup(f => f.AuthenticateAsync(It.IsAny<HttpAuthenticationContext>(), It.IsAny<CancellationToken>()))
         .Returns(() => Task.FromResult<object>(null));
     mock.Setup(f => f.ChallengeAsync(It.IsAny<HttpAuthenticationChallengeContext>(),
         It.IsAny<CancellationToken>()))
         .Callback<HttpAuthenticationChallengeContext, CancellationToken>((c, t) =>
         {
             challenge.Invoke(c, t);
         })
         .Returns(() => Task.FromResult<object>(null));
     return mock.Object;
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:15,代码来源:AuthenticationFilterResultTests.cs

示例8: CreatePrincipalService

 private static IHostPrincipalService CreatePrincipalService(
     Action<IPrincipal, HttpRequestMessage> setCurrentPrincipal)
 {
     Mock<IHostPrincipalService> mock = new Mock<IHostPrincipalService>();
     mock.Setup(s => s.GetCurrentPrincipal(It.IsAny<HttpRequestMessage>())).Returns(CreateDummyPrincipal());
     mock.Setup(s => s.SetCurrentPrincipal(It.IsAny<IPrincipal>(), It.IsAny<HttpRequestMessage>()))
         .Callback<IPrincipal, HttpRequestMessage>((p, r) => { setCurrentPrincipal.Invoke(p, r); });
     return mock.Object;
 }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:9,代码来源:AuthenticationFilterResultTests.cs

示例9: DelayAction

 IEnumerator DelayAction(Action act, float delay)
 {
     yield return new WaitForSeconds(delay);
     act.Invoke();
 }
开发者ID:RohitMoni,项目名称:GGJ2016,代码行数:5,代码来源:WitchHit.cs

示例10: HandleException

        public static void HandleException(bool exceptionDefaultOrBeforeAwait, bool exceptionAfterAwait, Action action)
        {
            bool hasException = false;

            SetExceptionInjection(exceptionDefaultOrBeforeAwait, exceptionAfterAwait);
            try
            {
                action.Invoke();
            }
            catch (Exception ex)
            {
                hasException = true;
                Debug.WriteLine("Exception: {0}", ex.Message);
            }

            AssertTransactionNull();
            Assert.Equal<bool>(hasException, true);
            ResetExceptionInjection();
        }
开发者ID:hughbe,项目名称:corefx,代码行数:19,代码来源:AsyncTransactionScopeTests.cs

示例11: HandleSendAsyncCompletion

        private async void HandleSendAsyncCompletion(Task task, TimeSpan timeout, Action<object> callback, object state)
        {
            try
            {
                await task;
            }
            catch (Exception)
            {
                _pendingWritingMessageException = WebSocketHelper.CreateExceptionOnTaskFailure(task, timeout,
                    WebSocketHelper.SendOperation);
            }
            finally
            {
                if (WcfEventSource.Instance.WebSocketAsyncWriteStopIsEnabled())
                {
                    WcfEventSource.Instance.WebSocketAsyncWriteStop(WebSocket.GetHashCode());
                }

                callback.Invoke(state);
            }
        }
开发者ID:weshaggard,项目名称:wcf,代码行数:21,代码来源:WebSocketTransportDuplexSessionChannel.cs

示例12: HandleCloseOutputAsyncCompletion

 private async void HandleCloseOutputAsyncCompletion(Task task, TimeSpan timeout, Action<object> callback, object state)
 {
     try
     {
         await task;
     }
     catch (Exception)
     {
         _pendingWritingMessageException = WebSocketHelper.CreateExceptionOnTaskFailure(task, timeout, WebSocketHelper.CloseOperation);
     }
     finally
     {
         callback.Invoke(state);
     }
 }
开发者ID:weshaggard,项目名称:wcf,代码行数:15,代码来源:WebSocketTransportDuplexSessionChannel.cs

示例13: WriteEndOfMessageAsync

            public async void WriteEndOfMessageAsync(Action<object> callback, object state)
            {
                if (WcfEventSource.Instance.WebSocketAsyncWriteStartIsEnabled())
                {
                    // TODO: Open bug about not emitting the hostname/port
                    WcfEventSource.Instance.WebSocketAsyncWriteStart(
                        _webSocket.GetHashCode(),
                        0,
                        string.Empty);
                }

                var timeoutHelper = new TimeoutHelper(_closeTimeout);
                var cancelTokenTask = timeoutHelper.GetCancellationTokenAsync();
                try
                {
                    var cancelToken = await cancelTokenTask;
                    await _webSocket.SendAsync(new ArraySegment<byte>(Array.Empty<byte>(), 0, 0), _outgoingMessageType, true, cancelToken);

                    if (WcfEventSource.Instance.WebSocketAsyncWriteStopIsEnabled())
                    {
                        WcfEventSource.Instance.WebSocketAsyncWriteStop(_webSocket.GetHashCode());
                    }
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    if (cancelTokenTask.Result.IsCancellationRequested)
                    {
                        throw Fx.Exception.AsError(
                            new TimeoutException(InternalSR.TaskTimedOutError(timeoutHelper.OriginalTimeout)));
                    }

                    throw WebSocketHelper.ConvertAndTraceException(ex, timeoutHelper.OriginalTimeout,
                        WebSocketHelper.SendOperation);
                }
                finally
                {
                    callback.Invoke(state);
                }
            }
开发者ID:weshaggard,项目名称:wcf,代码行数:44,代码来源:WebSocketTransportDuplexSessionChannel.cs

示例14: OnDesignPanelFirstTimeActivated

        private void OnDesignPanelFirstTimeActivated(Action<XRDesignPanel> handler)
        {
            DesignMdiController.DesignPanelLoaded += (sender1, designLoadedArgs) =>
            {
                var designPanel = (XRDesignPanel)sender1;

                EventHandler activated = null;
                activated = (sender2, emptyArgs) =>
                {
                    // remove handler after the first time it is activated
                    designLoadedArgs.DesignerHost.Activated -= activated;
                    handler.Invoke(designPanel);
                };

                designLoadedArgs.DesignerHost.Activated += activated;
            };
        }
开发者ID:GeniusCode,项目名称:GeniusCode.XtraReports.Designer,代码行数:17,代码来源:MessagingDesignForm.cs

示例15: BeginInvoke

 /// <summary>
 /// Invoke in UI thread.
 /// </summary>
 public void BeginInvoke(Action a)
 {
     a.Invoke();
 }
开发者ID:evnik,项目名称:UIFramework,代码行数:7,代码来源:Dispatcher.Abstract.cs


注:本文中的Action.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。