Note that there are some explanatory texts on larger screens.

plurals
  1. POThreads / Timers Troubles While Creating System Service Under VB.NET 4
    text
    copied!<p>I thought that creating a simple system service under VB .NET would be a piece of cake. Boy, was I wrong. First, I find general postings through Google that say you should use the Windows.Forms.Timer. Then, I found conflicting information that says you have to derive the timer from a timer class through code to make it work. Then, people are reporting all sorts of trouble using the various types of threads available. I can't debug threads using the VS 2010 Just-in-Time debugger for obvious reasons (although, I don't know if there is an alternate method to doing this). Wow, how confusing all this is when there is no definitive guide...</p> <p>My project is an application launcher (similar to cron) that will fire off periodically within a certain amount of seconds. I am trying to use the Process.Start() method. I have a Beep() function as the first instruction, and the Process.Start, along with a Process.WaitForExit method to make it block as the last instruction. I had my code doing this through timers, but now I am starting to use threads. No difference in execution. The over-ridden OnStart method does kick off (as I am certain through debugging), but nothing ever happens when starting the service in production, as if it were ignoring all my code. Putting loops and logic in the OnStart method yields a process that won't start. I know it is a threading issue, but I also know it must be mandatory to use threads. I am now dumbfounded as to how to make this work. I am curious to know the solution.</p> <p>In addition to the service class, I have a ServiceInstaller and ProcessInstaller implemented that I copied verbatim from MSDN.</p> <p>Here is some of the code I am trying to work with. Note that this simply reflects the current state of my code in trying to implement the logic within a thread instead of a timer (which to me would be optimal):</p> <pre><code> Dim config As String Dim configValues(2) As String Dim objReader As System.IO.StreamReader Dim interval As Integer Dim launchProcess As Process While True Beep() ' This sub runs every time the elapsed milli-seconds of the timer pass ' Sp add your code here. config = "30 c:\WiFiDropOutFix\start.vbs" Try objReader = New System.IO.StreamReader("C:\WiFiDropOutFix\config.txt") config = objReader.ReadToEnd objReader.Close() Catch ex As Exception End Try configValues = config.Split(New Char() {" "c}) interval = Convert.ToInt32(configValues(0)) If Not interval &gt; 0 And Not interval &lt; 61 Then interval = 10 End If launchProcess = Process.Start(configValues(1)) launchProcess.WaitForExit() Thread.Sleep(interval * 1000) End While End Sub </code></pre> <p>Here is my OnStart Code by Request:</p> <pre><code>Protected Overrides Sub OnStart(ByVal args() As String) appLaunchLogicThread = New Thread(AddressOf appLaunchLogic) appLaunchLogicThread.Start() End Sub </code></pre> <p>TIA.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload