1-) C# - windows servise
new windows services oluşturduktan sonra -> sağtık ->add installer->tıkla ve
--servicesprocess den Account propertieste onu localservice yap
--serviceinstaller1 den serviceName e isim felan ver
net start "RmosCloudService"
0-) servisi silmek için --> sc delete “servis adı”
1-)c#->projene-> sag tık rebuıld de
2-)cmd->yönetici olarak çalıştır ve "installutil pathi" "dosya yolu.exe"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>installutil E:\WindowsService1.exe
3-)silmek için yine cmd ye ->"installutil pathi" /u "dosya yolu.exe"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>installutil /u E:\WindowsService1.exe
servisin yüklü olduğunu anlamak için görev yöneticisi->hizmetler->hizmetleri aç dan bakabilirsin
eğer dosya yolunu bulamıyorsa onu kopyala exe yi kolay path e at oradan yukle
linkten bakabilirsin
1-)http://www.mesutx.com/tag/c-windows-service-uygulamasi/
2-)http://alieser.net/c-ile-windows-service-1/
---------------SONRADAN EKLENDİ------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace MyFirstService {
public partial class Service1: ServiceBase {
Timer timer = new Timer(); // name space(using System.Timers;)
public Service1() {
InitializeComponent();
}
protected override void OnStart(string[] args) {
WriteToFile("Service is started at " + DateTime.Now);
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 5000; //number in milisecinds
timer.Enabled = true;
}
protected override void OnStop() {
WriteToFile("Service is stopped at " + DateTime.Now);
}
private void OnElapsedTime(object source, ElapsedEventArgs e) {
this.timer.Stop(); // bunu ben ekledim eğer 5 sn de işi bitmezse girmesin diye
WriteToFile("Service is recall at " + DateTime.Now);
this.timer.Start(); // bunu ben ekledim eğer 5 sn de işi bitmezse girmesin diye
}
public void WriteToFile(string Message) {
string path = AppDomain.CurrentDomain.BaseDirectory + "\\Logs";
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Logs\\ServiceLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".txt";
if (!File.Exists(filepath)) {
// Create a file to write to.
using(StreamWriter sw = File.CreateText(filepath)) {
sw.WriteLine(Message);
}
} else {
using(StreamWriter sw = File.AppendText(filepath)) {
sw.WriteLine(Message);
}
}
}
}
}