Esempio n. 1
0
        private void CreateActor(object cancellationToken)
        {
            ActorId    actorId   = ActorId.CreateRandom();
            ITestActor testActor = ActorProxy.Create <ITestActor>(actorId);

            testActor.SetCountAsync(10, (CancellationToken)cancellationToken).Wait();
        }
        /// <summary>
        /// This is the main entry point for your service instance.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                // TODO: Replace the following sample code with your own logic
                //       or remove this RunAsync override if it's not needed in your service.

                long       iterations = 0;
                ITestActor actor      = ActorProxy.Create <ITestActor>(ActorId.CreateRandom());
                while (true)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    ServiceEventSource.Current.ServiceMessage(this.Context, $"{nameof(TestStateless)} Working-{++iterations}");
                    await actor.SetCountAsync((int)iterations, cancellationToken);

                    await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
                }
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.ServiceMessage(this.Context, $"Exception: {ex}");
                throw;
            }
        }