The New Code

For this example we will be adding some very simple threading code. The code will write an event into the event log database similar to the way we did in Chapter 1. However, we will use the new thread method to perform the work and we will use the current <OnStop> code to clean up the thread and specify that the service is shutting down.

Thread Function Code

The first thing we must do is create the thread function or method. In the Tutorials.vb code file, create the method shown in Example 2-2.

Example 2-2. Simple thread function.

Private Sub ThreadFunc()
   Try
   Catch tab as ThreadAbortException
   Catch ex as Exception
   Finally
   End try
End Sub

In this example, I am creating a method called <ThreadFunc>. As I mentioned, threads can only access ...

Get Programming Windows® Services with Microsoft® Visual Basic® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.