//1º passo
/// AssemblyInfo.cs setar o [assembly: ComVisible(false)] para true
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("MyNewService")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("internet")]
[assembly: AssemblyProduct("MyNewService")]
[assembly: AssemblyCopyright("Copyright © internet 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("0acab768-72c0-42f9-81e4-5176435afc0f")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//2º passo
//inclua um app.config para o caso de usar conexoes com banco de dados
xml version="1.0" encoding="Windows-1252"?>
<configuration>
<appSettings>
<add key="Main.ConnectionString" value="data source=VOLKDEV01;initial catalog=ERP;UID=sa;PWD=futureway" />
appSettings>
configuration>
//3º passo um exemplo de um windowsservice ja montado
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.EnterpriseServices;
using da;
using db;
namespace MyNewService
{
public partial class MyNewService : ServiceBase
{
private System.Timers.Timer TempoNovo = new System.Timers.Timer(5000);
public MyNewService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("MeuLogTeste"))
{
System.Diagnostics.EventLog.CreateEventSource("MeuLogTeste", "MeuLogTeste");
}
eventLog1.Source = "MeuLogTeste";
eventLog1.Log = "MeuLogTeste";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
eventLog1.WriteEntry("Iniciando Componente",EventLogEntryType.Error);
TempoNovo.Enabled = true;
TempoNovo.Elapsed += new System.Timers.ElapsedEventHandler(testTimer_Elapsed);
}
private void testTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
using (dbDevolucao objectDevolucao = new dbDevolucao())
{
objectDevolucao.CodigoCliente = 1;
objectDevolucao.CodigoSituacaoDevolucao = 3;
objectDevolucao.DataDevolucao = DateTime.Now.AddDays(10);
objectDevolucao.CodigoUsuarioCriacao = 1;
objectDevolucao.Insert();
eventLog1.WriteEntry("Tempo Novo : " + DateTime.Now.ToString(), System.Diagnostics.EventLogEntryType.Warning);
}
}
}
}
//4º passo
//compilar o projeto e instalar
//entrar no Visual studio console aplication e usar o installutil.exe [path + nomedoservico.exe]
//para desinstalar installutil.exe /u [path + nomedoservico.exe]
//ai é so correr pro abraço..
|