Exemple #1
0
        /// <summary>
        /// Runs the services and waits for termination.
        /// </summary>
        /// <param name="cancellationToken">
        /// The cancellation token.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the work performed.
        /// </returns>
        private static async Task Run(CancellationToken cancellationToken)
        {
            try
            {
                var factory = new ServiceFactory();
                Console.WriteLine("Initializing runtime.");
                var timeout = TimeSpan.FromMinutes(1);
                using (var fabric = await FabricRuntime.CreateAsync(timeout, cancellationToken))
                {
                    Console.WriteLine("Registering services.");
                    await
                        fabric.RegisterStatelessServiceFactoryAsync(
                            Service.ServiceTypeName,
                            factory,
                            timeout,
                            cancellationToken);

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(OrleansFabricSilo).Name);
                    Console.WriteLine("Services running.");
                    await Task.WhenAny(factory.Stopped, cancellationToken.WhenCancelled());
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e);
                throw;
            }
            finally
            {
                Console.WriteLine("Terminating.");
            }
        }