service woes

I'm working on a .net service that will basically perform a daily copy/extract from one server to another.
Where I'm stuck now is that it seems if I have any 'meat' in my copy routine, it simply gets skipped altogether, so I'm unsure what I've done wrong.

The basics of my code follows:
Shared tmr As New System.Timers.Timer(10000)
Shared blnCopyInProgress As Boolean = False
Protected Overrides Sub OnStart(ByVal args() As String)
     tmr.Enabled = True
     AddHandler tmr.Elapsed, AddressOf tmr_Tick
End Sub 
Protected Overrides Sub OnStop()
     SendMail("Service has stopped.")
     tmr = Nothing
End Sub 
Shared Sub tmr_Tick(ByVal source As Object, ByVal e As Timers.ElapsedEventArgs)
     If blnCopyInProgress Then Exit Sub
     If tmr.Interval <> 600000 Then tmr.Interval = 600000 'set timer to test every 10 minutes (going forward)
     If Today.DayOfWeek = DayOfWeek.Saturday Or Today.DayOfWeek = DayOfWeek.Sunday Then Exit Sub 'Don't run on the weekends
      fileDate = Today.Year & Today.Date.ToShortDateString.Substring(0, 2) & Today.Date.ToShortDateString.Substring(3, 2)
      strSrcFile = strSource & fileDate & fileName.Replace(".MDB", ".zip")
      If File.Exists(strSrcFile) Then CopyData()
End Sub
'Here's the 2 variations of CopyData - this first one will run - but all it does is send an email alert.  The second one 
'won't run 'at all' - I get no email alert, even though that's all it's doing before it exits the sub.  What could be wrong here?
Shared Sub CopyData()
     SendMail("made it this far")
End Sub
' or... 
Shared Sub CopyData()
     SendMail("made it this far")
     Exit Sub
     blnCopyInProgress = True
     Dim sc As Shell32.ShellClass = New Shell32.ShellClass
     Dim sf As Shell32.Folder = sc.NameSpace(strSrcFile)
     Dim df As Shell32.Folder = sc.NameSpace(strTarget)
     Dim fi As Shell32.FolderItems = sf.Items
     Dim strTgtFile As String = strTarget & fileDate & fileName.Replace("MDB", "ZIP")
          If File.Exists(strTarget & fileName) Then File.Delete(strTarget & fileName)
          File.Move(strSrcFile.Replace(strSource, strTarget), strTarget & fileName)
          WriteEvent("Sleeping for 20 hours")
          WriteEvent("Failed to extract audit data.", EventLogEntryType.Error)
     End Try
     fi = Nothing
     df = Nothing
     sf = Nothing
     sc = Nothing
     blnCopyInProgress = False
End Sub

Open in new window

LVL 67
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyAuthor Commented:
Note - while I have two copies of that subroutine - I only have one at a time when the service is launched. :^)
How about adding an error handler to the timer elapsed handler so any exceptions get either logged to a file or the event log?  And I usually find the quickest way to troubleshoot something like this is to start the service, attach the debugger, and then watch what happens.
sirbountyAuthor Commented:
I had it loaded up with event logging (removed here for simplicity) and it seems if I have any other executions in that sub, it fails...

I'm a bit new at creating services though - when you say attach the debugger, what are you referring to?  I'd love to step through this code rather than 'hope for the best'...
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Build and install a debug version with maybe a 60 second delay.  Start Visual Studio and then start the service.  You then have 60 seconds to do this...

From in Visual Studio, Tools - Attach to Process
Show processes from all users (turn this on)
Select your service
Set a breakpoint in the handler code.
Wait and hopefully it breaks in a few seconds.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
Hmm - never knew about that.
It seemed to work, cause the debugger was then showing it was running (after the service started).
However, I get some exclaimation points on my break lines that no symbols are loaded.

Interestingly enough, it gets through farther from this machine (at least to line 35 above).
ClickOnce was turned on (by default) - I stopped that thinking that the signing could be a problem with the target workstation...not really sure - you?
sirbountyAuthor Commented:
Well, either way it works fine on this PC - so what could prevent it from getting to the Copy sub on the other PC?
They're both the same OS, with same patches, etc...  
I forget the details on attaching to a service - maybe it works better to install the service from the location you built it.  Regardless, I would hazard a guess at a permissions problem on the other box.  You could try remote debugging but I'm no help with that.  I'm running out the door for the day so I'll just suggest logging messages to deduce where it goes wrong, particularly log something at the start of the handler (to verify the logging works) and then log something in a catch block (it seems as though there must be an exception happening).  Good luck  :-)
sirbountyAuthor Commented:
Yep, been doing all that - I've been logging and emailing myself - neither make it.  It's like it never hits the copy routine at all (unless it's pracically empty).
Doubtful that it's perms - same account on both and the workstations are both in the same OU.
I'll keep digging at it tho...thanx.
sirbountyAuthor Commented:
remote monitor was fairly easy to setup and I attached fine, but the same issue with symbols not loaded prevents it from hitting any breakpoints...anyone have any idea on that?
sirbountyAuthor Commented:
Well, I lucked out - forgot that I'd installed vs on that other workstation, so I just reproduced the code there and it's working 'locally' as it was before on this system.
I would like to know what the hang up was, but am glad to put it behind me just the same.
Although I don't think the original problem was resolved, I do appreciate your assistance and am grateful that I learned something new here.  That said, I would like to still offer you half the points for your time and effort.

If you would agree to that, post here and I'll take care of the adjustment.  
In any event - thanx very much.  Glad to come away from this without too many war wounds. :^)
sirbountyAuthor Commented:
Oh - and one other change I had to make...
I still had to put my Copy routine's declarations 'inside' the try/catch...odd, but it wouldn't work until I did...
That's fine.  The declarations you've got are doing initialization also so yes, they can throw exceptions.  Glad you got resolved it.  Maybe some other time we'll figure out the attaching-the-debugger problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.