PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD20]Background Service Executable
[WD20]Background Service Executable
Iniciado por guest, 11,nov. 2015 10:12 - 4 respuestas
Publicado el 11,noviembre 2015 - 10:12
Hi all,
I'm trying to create a simple background service that just waits for a socket connection from a client, accepts it and creates a thread for listening purposes to that client.
Using the Debug Mode of windev makes it work like a charm, never skips a beat, but when i try to run the executable, after creating it through the wizard, it automatically goes to the closing event of the service, without even passing once in the "Running the service of NameOfMyService", which is the main event. Below there's the code that i wrote:

//initializing ServiceHelloWorld
CONSTANT
SName = "ServerRF"
Port = 2100
END
IF SocketCreate(SName,Port) THEN
SocketChangeTransmissionMode(SName,SocketNoEndTag)
ELSE
EndProgram("Errore di attivazione connessione")
END


//Running the service of ServiceHelloWorld
IF SocketWaitForConnection(SName) THEN
channel is string
channel = SocketAccept(SName)
IF channel <> "" THEN
ThreadExecute(channel,threadNormal,WaitMessage,channel)
ELSE
Error(ErrorInfo())
END
END

Have i done something stupid? If so, sorry, i'm a newbie about services, so any help would be VERY appreciated
Publicado el 11,noviembre 2015 - 10:19
Yaku,

I would add an WHEN_EXCEPTION around the code you mentioned.
And use ServiceWriteEventLog() to see the exception message in the window event logs.

Maybe there is some info there already, done by the Windev framework?
Publicado el 11,noviembre 2015 - 10:32
Hi Arie,
I've tried to add these lines of code that i've taken from the example provided by Windev:

WHEN EXCEPTION
ServiceWriteEventLog(ExceptionInfo,elError)
END

I've tried to place them at the beginning of the init of the project, at the beginning of the loop event, and even in both cases, but the result remains the same, it just jumps over the loop event...
Tried also to look into the "event register" of windows, and no mentioning of my service.
Maybe i'm doing something wrong with the wizard for the exe?
Publicado el 11,noviembre 2015 - 11:06
Yaku,
are you sure it is running in the first place?
Can you start and stop the service from services.msc

I have a service running and took the service-example as a base for mine.
c:\WinDev 19 32\Examples\Training\WD Service\
Maybe you can try that one first to see what happens?
Publicado el 11,noviembre 2015 - 11:18
Arie,
Yeah, you were right, i've stupidly tried to run the exe straight away instead of installing it first...so, after creating the setup and running it, the service kinda works.
Thank you so much!