Downloads  |  Buy

How to create a windows service [Solved]

How to create a windows service [Solved]

Postby sancar » June 26th, 2018, 6:59 am

i cannot take AutomaticUpdaterBackend Version. and dont autoupdate. Anyone tell me, youtube video for windows service sample?
sancar
 

Re: windows service

Postby Wyatt » June 26th, 2018, 7:53 am

No. Use google. There are a thousand examples of creating a simple Windows Service in C#:

https://www.google.com/search?q=c%23+windows+service+stub&ie=utf-8&oe=utf-8
User avatar
Wyatt
Site Admin
 
Posts: 6053
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: windows service

Postby sancar » June 26th, 2018, 8:03 am

i am sory, i can start windows service and runnung. But wyUpdate dont autoupdate
sancar
 

Re: windows service

Postby Wyatt » June 26th, 2018, 8:07 am

More information is needed. Saying it doesn't work is not helpful.

1. Version numbers.
2. OS used.
3. Exactly how you're calling things.
4. Exactly what you expect to happen.
5. What is actually happening.
6. Error code you're getting.


Best place to start is here: https://wyday.com/wybuild/help/walkthrough.php
User avatar
Wyatt
Site Admin
 
Posts: 6053
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: windows service

Postby sancar » June 26th, 2018, 8:16 am

hello my test windows service code is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using wyDay.Controls;

namespace WyBuildWindowsServisTest
{
public partial class EmreWinService : ServiceBase
{
public EmreWinService()
{
InitializeComponent();
}


static AutomaticUpdaterBackend auBackend;

protected override void OnStart(string[] args)
{

auBackend = new AutomaticUpdaterBackend
{
//TODO: set a unique string.
// For instance, "appname-companyname"
GUID = "491ba093-b852-4e18-8526-cf05f7febfc1",

// With UpdateType set to Automatic, you're still in
// charge of checking for updates, but the
// AutomaticUpdaterBackend continues with the
// downloading and extracting automatically.
UpdateType = UpdateType.Automatic,

// We set the service name that will be used by wyUpdate
// to restart this service on update success or failure.
ServiceName = this.ServiceName//EmreWinService
};
auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled;
//auBackend.UpdateSuccessful += auBackend_UpdateSuccessful;

//TODO: use the failed events for logging & error reporting:
// CheckingFailed, DownloadingFailed, ExtractingFailed, UpdateFailed

// Initialize() and AppLoaded() must be called after events have been set.
// Note: If there's a pending update to be installed, wyUpdate will be
// started, then it will talk back and say "ready to install,
// you can close now" at which point your app will be closed.
auBackend.Initialize();
auBackend.AppLoaded();

if (!auBackend.ClosingForInstall)
{
// sees if you checked in the last 10 days, if not it rechecks
CheckEvery10Days();

//Note: Also, since this will be a service you should call
// CheckEvery10Days() from an another thread (rather
// than just at startup)

//TODO: do your normal service work
}



EventLog.WriteEntry("Test Service start");

EventLog.WriteEntry("Test Service v13");

string verNo = string.Empty;
if (!string.IsNullOrEmpty(auBackend.Version))
{
verNo += "Version => " + auBackend.Version + " - ";
}

if (!string.IsNullOrEmpty(auBackend.Changes))
{
verNo += "Changes => " + auBackend.Changes + " - ";
}
if (!string.IsNullOrEmpty(auBackend.GUID))
{
verNo += "GUID => " + auBackend.GUID + " - ";
}
//if (!string.IsNullOrEmpty(auBackend.LastCheckDate))
{
verNo += "LastCheckDate => " + auBackend.LastCheckDate + " - ";
}

if (!string.IsNullOrEmpty(auBackend.RawChanges))
{
verNo += "RawChanges => " + auBackend.RawChanges + " - ";
}


if (!string.IsNullOrEmpty(auBackend.ServiceName))
{
verNo += "ServiceName => " + auBackend.ServiceName + " - ";
}


if (!string.IsNullOrEmpty(auBackend.wyUpdateCommandline))
{
verNo += "wyUpdateCommandline => " + auBackend.wyUpdateCommandline + " - ";
}


if (!string.IsNullOrEmpty(auBackend.wyUpdateLocation))
{
verNo += "wyUpdateLocation => " + auBackend.wyUpdateLocation + " - ";
}


EventLog.WriteEntry("Service Version => " + verNo + " - " + this.ServiceName);

GuncellemeleriKontrolEt();

DonguyeDevam();



}

static void GuncellemeleriKontrolEt()
{
new Thread(() => {
try
{
while (true)
{
// Only ForceCheckForUpdate() every N days!
// You don't want to recheck for updates on every app start.

if ((DateTime.Now - auBackend.LastCheckDate).TotalMinutes > 5 && auBackend.UpdateStepOn == UpdateStepOn.Nothing)
{
auBackend.ForceCheckForUpdate();
}
Thread.Sleep(10000);
}
}
catch (Exception ex)
{

GuncellemeleriKontrolEt();
}
}).Start();
// Only ForceCheckForUpdate() every N days!
// You don't want to recheck for updates on every app start.

if ((DateTime.Now - auBackend.LastCheckDate).TotalMinutes > 5 && auBackend.UpdateStepOn == UpdateStepOn.Nothing)
{
auBackend.ForceCheckForUpdate();
}
}


static void CheckEvery10Days()
{
// Only ForceCheckForUpdate() every N days!
// You don't want to recheck for updates on every app start.

if ((DateTime.Now - auBackend.LastCheckDate).TotalMinutes > 5 && auBackend.UpdateStepOn == UpdateStepOn.Nothing)
{
auBackend.ForceCheckForUpdate();
}
}
static void auBackend_ReadyToBeInstalled(object sender, EventArgs e)
{

// ReadyToBeInstalled event is called when
// either the UpdateStepOn == UpdateDownloaded or UpdateReadyToInstall

if (auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall)
{

//TODO: Delay the installation of the update until
// it's appropriate for your app.

//TODO: Do any "spin-down" operations. auBackend.InstallNow() will
// exit this process using Environment.Exit(0), so run
// cleanup functions now (close threads, close running programs,
// release locked files, etc.)

// here we'll just close immediately to install the new version
auBackend.InstallNow();
}
}

protected override void OnStop()
{
EventLog.WriteEntry("Test Service stop");
}


private void DonguyeDevam()
{
Thread.Sleep(10000);
new Thread(() =>
{

try
{
while (true)
{

Thread.Sleep(1000);
}
}
catch (Exception)
{

DonguyeDevam();
}



}).Start();

}



}
}

i want auto update windows service.
this picture is revision of wyBuild
https://ibb.co/njXON8

and this picture is event log
https://ibb.co/cXXUvT

i dont have any error.
i will take new revision (v11) service dont update himself
sancar
 

Re: windows service

Postby Wyatt » June 26th, 2018, 8:23 am

Honestly, just use wyUpdate from the service. Less moving parts and easier to use (and same end-result): https://wyday.com/wybuild/help/silent-update-windows-service.php

Don't bother with the AutomaticUpdater.
User avatar
Wyatt
Site Admin
 
Posts: 6053
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire


Return to Open Source Support