コード例 #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            SecureExecute(() =>
            {
                if (timer != null)
                {
                    throw new Exception("Already created");
                }

                var number = ++currentNumber;
                timer      = AsyncHelper.RunSync(() => Tasks.AsyncTimer.CreateAsync(
                                                     TimeSpan.FromSeconds(0.5),
                                                     TimeSpan.FromSeconds(0.25),
                                                     true,
                                                     true,
                                                     elapsedActions: new AsyncTimerActionDelegate [] { cancellationToken =>
                                                                                                       {
                                                                                                           Log($"Invoked {number}");
                                                                                                           return(Task.CompletedTask);
                                                                                                       } }));
                timer.ExceptionOccurred += (del, exception) =>
                {
                    Log($"Exception during invocation {number}{Environment.NewLine}{exception}");
                    return(Task.CompletedTask);
                };
                Log("Created");
            });
        }
コード例 #2
0
 private void btnDispose_Click(object sender, EventArgs e)
 {
     SecureExecute(() =>
     {
         timer.Dispose();
         timer = null;
     });
 }