New to windows services

WellsCarrie

Well-known member
Joined
Jul 12, 2005
Messages
95
Location
Arkansas
Programming Experience
5-10
I need to write an VB.Net app that can be started and stopped by the "robot" application running on the department's production server.

The application will basically read from the manufacturing AS400 database, process the record set(s) and then load the process results into the shipping oracle database.



It needs to run with out an interface "Once A Day" at 3:00 pm.



My boss insists that the robot has to be able to start and stop the processing in case of any one of the 1000+ processes (mine included) running concurrently cause problems.



Now my intent was to write a windows service using a system.timer object to fire off my data processing module, but the timer object works in milliseconds and while I could calculate the number of milliseconds in a 24 hour period it seems to be the wrong way to do this.



So, any other ideas on how to accomplish this goal?



I have been an ASP/ASP.NET developer for 7 years. I have only written 5 "VB" apps in my life 4 VB6 console apps and 1 VB.Net console app. Any help or suggestions you guys have would be GREATLY appreciated!


THANKS!
 
Last edited:
Absolutely nothing wrong with using a Timer with a 24 hour interval. Despite the fact that there is some incorrect information in the help documentation, the Timer.Interval property is an Integer. This means it has a maximum value of 2147483647, so 24 * 60 * 60 * 1000 = 86400000 milliseconds in a day is no problem.
 
Just to clarify something about Timers.

The Interval property of a System.Windows.Forms.Timer is of Type Integer. I would suggest that you use this class in a single-threaded Windows app.

The Interval property of a System.Timers.Timer is of type Double. I would suggest that you use this class in a single-threaded Console app or Windows service.

A System.Threading.Timer has no Interval property but can accept an interval through the Change method as an Integer, Long, TimeSpan or UInt32. I would suggest that you use this class in a multi-threaded environment.
 
I'm using the System.Timers.Timer for the service.

I do have another question though. I want to ensure that a datbase connection I'm using to do the work really does get closed and desposed of if the service should get shut down.

I'm using the following code:
If connDISMABEL.State = ConnectionState.Open Then

If connDISMABEL.State = ConnectionState.Executing Or _

connOhio.State = ConnectionState.Fetching
Then

For i = 0 To 10000

IfNot connDISMABEL.State = ConnectionState.Executing Or _

connDISMABEL.State = ConnectionState.Fetching
Then

connDISMABEL.Close()

connDISMABEL.Dispose()

ExitFor

EndIf

Next

Else

connDISMABEL.Close()

connDISMABEL.Dispose()

EndIf

EndIf

If connOhio.State = ConnectionState.Open Then

If connOhio.State = ConnectionState.Executing Or _

connOhio.State = ConnectionState.Fetching
Then

For i = 0 To 10000

IfNot connOhio.State = ConnectionState.Executing And _

Not connOhio.State = ConnectionState.Fetching Then

connOhio.Close()

connOhio.Dispose()

EndIf

ExitFor

Next

Else

connOhio.Close()

connOhio.Dispose()

EndIf

EndIf


What I can't figure out is what to do if I'm not allowing enough time to pass in my loop for the service to complete what it got started and close the connection properly?

My ideal is to KILL what ever execute or read the connection is doing and then close and dispose of the object properly. Is ther a way to KILL a data reader or data execute mid way?

Sorry if I'm asking too many questions.

Thanks!
 
The connection object has no finalize method and .net will not let me do a dispose on an open connection.

I need to be able to find the command that is running and stop it first before the connection is closed and disposed.

Thanks!
 
Back
Top