CodeXchange Saturday, December 21, 2024
Home
What's it?
Download
Register
My Snippets
Add Snippet
Search
Faq
Contact Us
Sponsors

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
Code:
//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..

Snippet Comments
Comments:
No comments for this snippet

Other snippets that may interest you..
Related Snippets
TDT - GridPage - Page_Init (C#)
CustomValitaor (C#)
(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-2024 CodeXchange. Server version 1.0.3720.32855 Client Version 0.9.0.0

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: Saturday, December 21, 2024