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


C# Action.?.Invoke方法代码示例

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


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

示例1: ChildProgressBar

		internal ChildProgressBar(int maxTicks, string message, Action scheduleDraw, ProgressBarOptions options = null, Action<ProgressBarHeight> growth = null)
			: base(maxTicks, message, options)
		{
			_scheduleDraw = scheduleDraw;
			_growth = growth;
			_growth?.Invoke(ProgressBarHeight.Increment);
		}
开发者ID:codejnki,项目名称:shellprogressbar,代码行数:7,代码来源:ChildProgressBar.cs

示例2: RunSyncOrAsyncWithLock

        public static void RunSyncOrAsyncWithLock(object lockObject, Action action, Action whenComplete = null)
        {
            if (Monitor.TryEnter(lockObject))
            {
                try
                {
                    action();
                }
                finally
                {
                    Monitor.Exit(lockObject);
                }

                whenComplete?.Invoke();
            }
            else
            {
                MvxAsyncDispatcher.BeginAsync(() =>
                    {
                        lock (lockObject)
                        {
                            action();
                        }

                        whenComplete?.Invoke();
                    });
            }
        }
开发者ID:talisqualis,项目名称:MvvmCross-Build,代码行数:28,代码来源:MvxLockableObjectHelpers.cs

示例3: Parse

        public static IToken Parse(string text, int startPosition = 0, Action<IToken, int, string> callback = null)
        {
            if (string.IsNullOrWhiteSpace(text))
                return new NullToken();

            if (text.StartsWith("'") && text.IndexOf('\'', 1) <= 0)
                return new StringToken(text.Substring(1));

            List<string> blocks = text.SplitIntoBlocks(new[] {'\'', '\'', '"', '"', '^', '^', '{', '}', '(', ')'}, true,
                StringUtils.DelimiterInclude.IncludeSeparately);

            string simplifed = "";
            List<IToken> subResults = new List<IToken>();

            int currentPosition = startPosition;
            for (int i = 0; i < blocks.Count; i += 3)
            {
                string start = blocks[i];
                string entry = blocks[i + 1];
                IToken subResult = null;
                switch (start)
                {
                    case "\"":
                    case "'":
                        subResult = new StringToken(entry);
                        callback?.Invoke(subResult, currentPosition, "'" + entry + "'");
                        break;
                    case "^":
                        subResult = Parse(entry);
                        callback?.Invoke(subResult, currentPosition, "'" + entry + "'");
                        break;
                    case "{":
                        subResult = new ExpressionToken(null, new SubstitutionOperator(), Parse(entry));
                        callback?.Invoke(subResult, currentPosition, "{" + entry + "}");
                        break;
                    case "(":
                        subResult = Parse(entry, currentPosition + 1, callback);
                        break;
                    default:
                        simplifed += entry;
                        break;
                }
                if (subResult != null)
                {
                    simplifed += $"█{subResults.Count}█";
                    subResults.Add(subResult);
                }
                if (callback != null)
                    currentPosition += start.Length + entry.Length + blocks[i + 2].Length;
            }

            IToken result = ParseExpressionNoBrackets(simplifed, startPosition, callback);
            result = SubstituteValues(result, subResults);

            return result ?? new StringToken(text);
        }
开发者ID:MotorViper,项目名称:FormGenerator,代码行数:56,代码来源:TokenGenerator.cs

示例4: Show

        public Task Show(Action OnPresented = null)
        {
            if (showTask != null)
            {
                showTask.TrySetResult(false);
                showTask.TrySetCanceled();
            }
            else {
                showTask = new TaskCompletionSource<bool>();
            }
            adsInterstitial = new Interstitial(CrossAdmobManager.AdmobKey);
            var request = Request.GetDefaultRequest();
            adsInterstitial.AdReceived += (sender, args) =>
            {
                if (adsInterstitial.IsReady)
                {
                    var window = UIApplication.SharedApplication.KeyWindow;
                    var vc = window.RootViewController;
                    while (vc.PresentedViewController != null)
                    {
                        vc = vc.PresentedViewController;
                    }
                    adsInterstitial.PresentFromRootViewController(vc);
                    OnPresented?.Invoke();
                }
            };

            adsInterstitial.ScreenDismissed += (sender, e) => {
                if (showTask != null)
                {
                    showTask.TrySetResult(adsInterstitial.IsReady);
					showTask = null;

                }
			};

			adsInterstitial.ReceiveAdFailed += (sender, e) =>
			{
				OnPresented?.Invoke();
				showTask.TrySetResult(false);
				showTask.TrySetCanceled();
				showTask = null;
			};

			if (testDevicesId != null)
			{
				testDevicesId.Add(Request.SimulatorId);
				request.TestDevices = testDevicesId.ToArray();
			}
            adsInterstitial.LoadRequest(request);
            return Task.WhenAll(showTask.Task);
        }
开发者ID:LosXamarinos,项目名称:Xamarinos.AdMob.FormsPlugin,代码行数:52,代码来源:AdsInterstitialImplementation.cs

示例5: CreateContainer

        protected ILifetimeScope CreateContainer(Action<ContainerBuilder> setupCallback = null)
        {
            var builder = new ContainerBuilder();

            var fakeEnvironment = builder.RegisterFake<IEnvironmentInformation>();

            fakeEnvironment
                .GetIsInDesignTime()
                .Returns(false);

            fakeEnvironment
                .GetIsDebugging()
                .Returns(true);

            builder.RegisterModule(
                new DefaultWiringModule(fakeEnvironment));

            builder.RegisterFake<IThreadDelay>();

            setupCallback?.Invoke(builder);

            return activeContainer = builder
                                         .Build()
                                         .BeginLifetimeScope();
        }
开发者ID:gitter-badger,项目名称:Shapeshifter,代码行数:25,代码来源:TestBase.cs

示例6: GetResourceStream

 public override void GetResourceStream(string resourcePath, Action<Stream> streamAction)
 {
     using (var input = Assets.Open(resourcePath))
     {
         streamAction?.Invoke(input);
     }
 }
开发者ID:ChebMami38,项目名称:MvvmCross-Plugins,代码行数:7,代码来源:MvxAndroidResourceLoader.cs

示例7: Measure

        /// <summary>
        /// Returns average microseconds an action takes when run for the specified runForMs
        /// </summary>
        /// <param name="fn">What to run</param>
        /// <param name="times">How many times to run for each iteration</param>
        /// <param name="runForMs">Minimum ms to run for</param>
        /// <param name="setup"></param>
        /// <param name="warmup"></param>
        /// <param name="teardown"></param>
        /// <returns></returns>
        public static double Measure(Action fn,
            int times = 1,
            int runForMs = 2000,
            Action setup = null,
            Action warmup = null,
            Action teardown = null)
        {
            setup?.Invoke();

            // Warmup for at least 100ms. Discard result.
            if (warmup == null)
                warmup = fn;

            GC.Collect();

            MeasureFor(() => warmup(), 100);

            // Run the benchmark for at least 2000ms.
            double result = MeasureFor(() =>
            {
                for (var i = 0; i < times; i++)
                    fn();
            }, runForMs);

            teardown?.Invoke();

            return result;
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:38,代码来源:PerfUtils.cs

示例8: RegisterDependencies

        public void RegisterDependencies(Action<ContainerBuilder> build)
        {
            var cb = new ContainerBuilder();
            build?.Invoke(cb);
            cb.Update(DependencyContainer);

        }
开发者ID:builttoroam,项目名称:applicationstates,代码行数:7,代码来源:RootApplication.cs

示例9: ConfirmActionAsync

        /// <summary>
        /// This will show a MessageDialog with a YES/NO option. It will run an action based on the actoin parameter.
        /// </summary>
        /// <param name="message">Message to show.</param>
        /// <param name="title">Title of the message.</param>
        /// <param name="yesAction">The action that should be run upon confirmation</param>
        /// <param name="noAction">The action that should be run upon rejection</param>
        /// <returns>true if user indicates "Yes", false otherwise</returns>
        static public async Task<bool> ConfirmActionAsync(string message, string title, Action yesAction, Action noAction = null)
        {
            var commandresult =
            await new MessageDialog(message, title)
                                {
                                       Commands =
                                       {
                                           new UICommand
                                           {
                                               Label = "Yes",
                                               Invoked = command => yesAction()
                                           },
                                           new UICommand
                                           {
                                               Label = "No",
                                               Invoked = command => noAction?.Invoke()
                                           }
                                       },
                                       DefaultCommandIndex = 1,
                                       CancelCommandIndex = 1,
                                       Options = MessageDialogOptions.AcceptUserInputAfterDelay,
                                }
            .ShowAsync();

            return commandresult.Label == "Yes";
        }
开发者ID:Toudahl,项目名称:SoftwareDesignHelper,代码行数:34,代码来源:ConfirmationBox.cs

示例10: MainPage

        public MainPage()
        {
            InitializeComponent();

            for (int i = 0; i < 20; i++)
            {
                var twnk = new TwinkleStar(i);
                _tinkleCanvas.Children.Add(twnk);
                _stars.Add(twnk);
            }

            for (int i = 0; i < 3; i++)
            {
                var ballon = new FloatingBallon(i);
                _tinkleCanvas.Children.Add(ballon);
            }

            _nextTapAction = () =>
            {
                _typeOfPresentWheel.Spin();
                _nextTapAction = null;
            };

            Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Title = "Grattis";

            _bandIO.Connect();
            _bandIO.Pulled += () =>
            {
                if ((DateTime.UtcNow - _lastAcccelerometerAction).TotalSeconds < 1)
                    return;
                _lastAcccelerometerAction = DateTime.UtcNow;
                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => _nextTapAction?.Invoke());
            };
        }
开发者ID:HeavyHenke,项目名称:Karin35,代码行数:34,代码来源:MainPage.xaml.cs

示例11: IsTrue

		public static void IsTrue( this bool target, Action action )
		{
			if ( target )
			{
				action?.Invoke();
			}
		}
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:7,代码来源:BooleanExtensions.cs

示例12: Display

        public static void Display(string text, Action dismissed = null)
        {
            var window = ((AppDelegate)UIApplication.SharedApplication.Delegate).Window;

            var alertView = new BlurredAlertView(text);
            var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.Dark);
            var blurView = new UIVisualEffectView(blur);
            blurView.Frame = new CGRect(0, 0, window.Frame.Width, window.Frame.Height);
            blurView.AutoresizingMask = UIViewAutoresizing.All;

            blurView.ContentView.Add(alertView.View);
            blurView.Alpha = 0;
            blurView.AutoresizingMask = UIViewAutoresizing.All;
            window.Add(blurView);

            UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseIn, () => blurView.Alpha = 1, null);

            alertView._button.GetClickedObservable().Take(1).Subscribe(_ => {
                UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseIn, () => blurView.Alpha = 0, () => {
                    blurView.RemoveFromSuperview();
                    alertView.View.RemoveFromSuperview();
                    dismissed?.Invoke();
                });
            });
        }
开发者ID:RaineriOS,项目名称:CodeHub,代码行数:25,代码来源:BlurredAlertView.cs

示例13: CreateTransient

        private InMemoryTestStore CreateTransient(Action initializeDatabase, Action deleteDatabase)
        {
            initializeDatabase?.Invoke();

            _deleteDatabase = deleteDatabase;
            return this;
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:7,代码来源:InMemoryTestStore.cs

示例14: CreateDefaultGlobalContainer

 internal static IObjectContainer CreateDefaultGlobalContainer(IRuntimeConfigurationProvider configurationProvider = null, Action<IObjectContainer> registerGlobalMocks = null)
 {
     var instance = new ContainerBuilder();
     var globalContainer = instance.CreateGlobalContainer(configurationProvider);
     registerGlobalMocks?.Invoke(globalContainer);
     return globalContainer;
 }
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:7,代码来源:TestObjectFactories.cs

示例15: GetSticker

		public void GetSticker (IceCream iceCream, Action<MSSticker> completion)
		{
			if (iceCream.Base == null || iceCream.Scoops == null || iceCream.Topping == null)
				throw new Exception ("Stickers can only be created for completed ice creams");

			// Determine the URL for the sticker.
			var fileName = $"{iceCream.Base.RawValue}{iceCream.Scoops.RawValue}{iceCream.Topping.RawValue}.png";
			var url = Path.Combine (cacheURL, fileName);

			// Check if the sticker already exists at the URL
			if (!NSFileManager.DefaultManager.FileExists (url)) {
				
				// Create the sticker image and write it to disk.
				var image = iceCream.RenderSticker (false);
				var imageData = image?.AsPNG ();
				if (image == null || imageData == null)
					throw new Exception ("Unable to build image for ice cream");

				try {
					File.WriteAllBytes (url, imageData.ToArray ());
				} catch {
					throw new Exception ("Failed to write sticker image to cach");
				}
			}

			NSError error;
			var sticker = new MSSticker (new NSUrl ($"file://{url}"), "Ice Cream", out error);

			if (error != null)
				throw new Exception ($"Failed to write image to cache, error: {error.LocalizedDescription}");

			completion?.Invoke (sticker);
		}
开发者ID:XiaomeiLI2020,项目名称:monotouch-samples,代码行数:33,代码来源:IceCreamStickerCache.cs


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