Created
August 31, 2016 21:55
-
-
Save gbellmann/2dcd1ddaed7c460dacede9b562812cd5 to your computer and use it in GitHub Desktop.
Service Fabric Stateless Service newly created from the template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Fabric; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.ServiceFabric.Services.Communication.Runtime; | |
using Microsoft.ServiceFabric.Services.Runtime; | |
namespace HelloWorldService | |
{ | |
/// <summary> | |
/// An instance of this class is created for each service instance by the Service Fabric runtime. | |
/// </summary> | |
internal sealed class HelloWorldService : StatelessService | |
{ | |
public HelloWorldService(StatelessServiceContext context) | |
: base(context) | |
{ } | |
/// <summary> | |
/// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. | |
/// </summary> | |
/// <returns>A collection of listeners.</returns> | |
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() | |
{ | |
return new ServiceInstanceListener[0]; | |
} | |
/// <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) | |
{ | |
// 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; | |
while (true) | |
{ | |
cancellationToken.ThrowIfCancellationRequested(); | |
ServiceEventSource.Current.ServiceMessage(this, "Working-{0}", ++iterations); | |
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment