CodeXchange Sunday, May 26, 2019
What's it?
My Snippets
Add Snippet
Contact Us

Website hosted by

Code Snippet Preview

Review the code snippet before inserting it on your project.

Snippet Metadata
Summary: Criar e Configurar WindosServices
Language: C#
Author: carlos martins
Author snippets RSS:
Culture: pt-BR
Bytes: 3036
Visual Studio 2005 Snippet:

Snippet Stats
Downloads: 0
Overall rating : 0
Average rating : Snippet rating

Snippet Preview
//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("")]
[assembly: AssemblyFileVersion("")]

//2º passo
//inclua um app.config para o caso de usar conexoes com banco de dados
xml version="1.0" encoding="Windows-1252"?>
                <add key="Main.ConnectionString" value="data source=VOLKDEV01;initial catalog=ERP;UID=sa;PWD=futureway" />
//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()
            if (!System.Diagnostics.EventLog.SourceExists("MeuLogTeste"))
                System.Diagnostics.EventLog.CreateEventSource("MeuLogTeste", "MeuLogTeste");
            eventLog1.Source = "MeuLogTeste";
            eventLog1.Log = "MeuLogTeste";
        protected override void OnStart(string[] 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;
                  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..

Snippet Comments
No comments for this snippet

Other snippets that may interest you..
Related Snippets
TDT - GridPage - Page_Init (C#)
CustomValitaor (C#)
Get the file extension from a file path or file name (VB.NET)
grab record from db and subtracts it from variable (VB.NET)

Copyright ©2009-2019 CodeXchange. Server version 1.0.3720.32855 Client Version

With from Barcelona

Most Helpful members
These are the members who have received the most points for their helpful samples
Zepho Zep
Robert Wagner
Galen Taylor

All time 'Hall of fame'
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
INI File Access (VB.NET)
Read XML from string into DataSet (C#)
Create Manifest File for your Application (VB.NET)
Round function to avoid banker's rounding (VB.NET)
Get Short and Long Path Names (VB.NET)
Sending Mail through authenticated SMTP server (C#)
One Way Hash for strings (C#)
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
How do I load an image from a URI address? (VB.NET)
Use our easy to use Visual Studio.NET addin client and start sharing code snippets with the CodeXchange community!
Refreshed: Sunday, May 26, 2019