Advertisement
loonerz

worker role

Jan 3rd, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Threading;
  6. using Microsoft.WindowsAzure.ServiceRuntime;
  7. using SiteMonitR.WorkerRole.Properties;
  8.  
  9. namespace SiteMonitR.WorkerRole
  10. {
  11.     public class WorkerRole : RoleEntryPoint, IService2
  12.     {
  13.         Thread thread;
  14.         Server server;
  15.  
  16.         public int GetResponseWorker()
  17.         {
  18.             int result = 0;
  19.             server.DoSomething("result is " + result);
  20.             return result;
  21.         }
  22.  
  23.         public override void Run()
  24.         {
  25.             Trace.WriteLine("SiteMonitR.WorkerRole entry point called", "Information");
  26.  
  27.             while (true)
  28.             {
  29.                 Thread.Sleep(Settings.Default.PingTimeout);
  30.                 server.Run();
  31.             }
  32.         }
  33.  
  34.         public override bool OnStart()
  35.         {
  36.             ServicePointManager.DefaultConnectionLimit = 12;
  37.  
  38.             // create the server
  39.             server = new Server(
  40.                 new TableStorageSiteUrlRepository(),
  41.                 new WorkerRoleHubConfiguration()
  42.                 );
  43.  
  44.             // run the server
  45.             thread = new Thread(new ThreadStart(() => server.Run()));
  46.             thread.Start();
  47.  
  48.             return base.OnStart();
  49.         }
  50.  
  51.         public override void OnStop()
  52.         {
  53.             thread.Abort();
  54.             server.Stop();
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement