Ir al contenido


Foto

Servicio en C#


  • Por favor identifícate para responder
3 respuestas en este tema

#1 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 10 marzo 2009 - 04:14

Hola

Tengo una aplicación hecha en C# y necesito que esa aplicación corra como servicio, alguien sabe como logro eso?

Salud OS
  • 0

#2 axesys

axesys

    Advanced Member

  • Moderadores
  • PipPipPip
  • 640 mensajes
  • LocationLos Mochis

Escrito 10 marzo 2009 - 05:43

Juan Pablo Garcia, escribió un excelente artí­culo de cómo crear servicios en C# paso a paso, se los recomiendo.

¿Cómo hacer un Servicio Windows en C#?
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 10 marzo 2009 - 05:48

Juan Pablo Garcia, escribió un excelente artí­culo de cómo crear servicios en C# paso a paso, se los recomiendo.

¿Cómo hacer un Servicio Windows en C#?


Muchas gracias amigo axesys, lo voy a seguir paso a paso (y)

Salud OS
  • 0

#4 cHackAll

cHackAll

    Advanced Member

  • Administrador
  • 599 mensajes

Escrito 11 marzo 2009 - 06:23



csharp
  1. using System;
  2. using System.IO;
  3. using System.Configuration.Install;
  4. using System.ComponentModel;
  5. using System.ServiceProcess;
  6. using System.Threading;
  7.  
  8. [RunInstallerAttribute(true)] // %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\Installutil.exe Service.exe
  9. public class _Installer : Installer // Service installer...
  10. {
  11. public _Installer()
  12. {
  13. ServiceProcessInstaller spi = new ServiceProcessInstaller();
  14. ServiceInstaller si = new ServiceInstaller(); 
  15. spi.Account = ServiceAccount.LocalSystem;
  16. si.StartType = ServiceStartMode.Automatic;
  17. si.Description = "cHackAll Service";
  18. si.ServiceName = "cServ";
  19. Installers.AddRange(new Installer[] { si, spi }); // install it
  20. }
  21. }
  22.  
  23. public class _Service : ServiceBase
  24. {
  25. public static void Main() // Entry point of process
  26. {
  27. ServiceBase.Run(new _Service()); // run service...
  28. }
  29.  
  30. Thread Thread = new Thread(new ThreadStart(delegate() // Our service thread
  31. {
  32. while (true) // condition
  33. {
  34. Thread.Sleep(1000); // sample
  35. using (FileStream fs = File.Open(@"c:\test.txt", System.IO.FileMode.Append))
  36. {
  37. fs.WriteByte(64);
  38. fs.Close();
  39. }
  40. }
  41. }));
  42.  
  43. #region Events...
  44.  
  45. protected override void OnStart(string[] args)
  46. {
  47. Thread.Start();
  48. }
  49.  
  50. protected override void OnPause()
  51. {
  52. Thread.Suspend();
  53. }
  54.  
  55. protected override void OnContinue()
  56. {
  57. Thread.Resume();
  58. }
  59.      
  60. protected override void OnStop()
  61. {
  62. Thread.Abort();
  63. }
  64.  
  65. #endregion
  66. }


  • 0




IP.Board spam blocked by CleanTalk.