I´m having the weirdest problem.
In my C# solution, I have a desktop test application, and a service application. On the start of both applications, I call the exact same methods, and the behaviour is completely different.
My desktop application is working just fine, reads a COM port, process that info, and then inserts that data on my DB.
The service application, read the COM port fine, but then the processing of the data is completely different, and after that it throws an SQLException because it is trying to convert wrong data(Specifficaly a datetime ’01/01/0001′)
I need this application to be a Service, I´m having the desktop app just to test it. I´ve been working on services for a while and I´ve never seen this behavior before.
How is it possible that the application and the service work so different calling the same functions using the EXACT same libraries?.
Here is the code:
-
Service:
protected override void OnStart() { csGPS.startGPSData(); Thread hiloEscuchar = new Thread(delegate() { csListener listener = new csListener(); listener.listenAutoCommand(); }); hiloEscuchar.Start(); Thread hiloEnviar = new Thread(delegate() { csSender.buscarComandos(); }); hiloEnviar.Start(); Thread hiloEnviarPosiciones = new Thread(delegate() { csSender.enviarPosiciones(); }); hiloEnviarPosiciones.Start(); } -
Desktop App:
private void btnComenzar_Click(object sender, EventArgs e) { csGPS.startGPSData(); Thread hiloEscuchar = new Thread(delegate() { csListener listener = new csListener(); listener.listenAutoCommand(); }); hiloEscuchar.Start(); Thread hiloEnviar = new Thread(delegate() { csSender.buscarComandos(); }); hiloEnviar.Start(); Thread hiloEnviarPosiciones = new Thread(delegate() { csSender.enviarPosiciones(); }); hiloEnviarPosiciones.Start(); lblEstado.Text = "STARTED"; btnComenzar.Enabled = false; }
I hope you guys can help me.
Thanks.
While the code may be the same, services run under an entirely different security context. They usually run under the
LocalSystemuser, and have no access to the desktop. This use also has very limited network access.You will need to debug your code as a service, or at least add some debug logging statements to try and figure out what behaves differently.