O'Reilly logo

Programming Windows® Services with Microsoft® Visual Basic® 2008 by Michael Gernaey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required