File monitor/copy code doesn't catch everything

File monitor/copy code doesn't catch everything

Post by TwistedPai » Sun, 25 Mar 2007 05:39:58


ll,
This is sort of a continuation of a previous post of mine. The code below
basically reads a registry key to get a path to a folder and it watches for
files created in that folder (only created). It also reads another registry
key for another path which is a destination path. When a file shows up, it
copies it off.

It actually works well . . . For small duty stuff but if for example I were
to copy in multiple small files simulteneously into the source folder, it
only copies the first one it sees. It sorta peeters out after that, and I
don't think it continues on copying.

Also, if I drop a large file -- 500MB or higher -- into the folder, it
starts copying, but if I drop another file in the folder during this time,
it doesn't pick it up. I don't think it even finished copying the large
file.

Just wanted to see if y'all could give me some direction/advice.

TIA,
Pair

Imports System.ServiceProcess

Imports System.Threading

Public Class Service1

Inherits System.ServiceProcess.ServiceBase

Dim DestDirectory As String

Dim WatchDirectory As String

Private Watchservice As New Thread(New
System.Threading.ThreadStart(AddressOf StartMonitor))

#Region " Component Designer generated code "

Public Sub New()

MyBase.New()

' This call is required by the Component Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call

End Sub

'UserService overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

' The main entry point for the process

<MTAThread()> _

Shared Sub Main()

Dim ServicesToRun() As System.ServiceProcess.ServiceBase

' More than one NT Service may run within the same process. To add

' another service to this process, change the following line to

' create a second service object. For example,

'

' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1,
New MySecondUserService}

'

ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}

System.ServiceProcess.ServiceBase.Run(ServicesToRun)

End Sub

'Required by the Component Designer

Private components As System.ComponentModel.IContainer

' NOTE: The following procedure is required by the Component Designer

' It can be modified using the Component Designer.

' Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

components = New System.ComponentModel.Container()

Me.ServiceName = "Service1"

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)

' Start the thread.

Watchservice.Start()

End Sub

Protected Overrides Sub OnStop()

' Add code here to perform any tear-down necessary to stop your service.

Watchservice.Abort()

End Sub

Private Sub StartMonitor()

Do

WatchDirectory =
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\CopyMon",
"Source", Nothing)

DestDirectory =
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\CopyMon",
"Destination", Nothing)

Dim watcher As New System.IO.FileSystemWatcher(WatchDirectory)

Dim result

AddHandler watcher.Created, AddressOf logchange

'Dim SourceFileNameObject As IO.WaitForChangedR
 
 
 

1. Creating a Catch-Everything Catch-All

2. catch(...) doesn't catch everything

I was looking for a way to just catch any exception throw. Given the
postings, it looks like catch(...) should do it, except it doesn't.
Maybe C++ is suppose to work this way, or maybe this is a bug in g++.

I have a small program to demonstrate below. I compiled on a RH9
system using g++ v3.4.5.

#include <iostream>

main()
{
try {
throw(1);
} catch (...) {
std::cerr << "Caught integer exception\n";
}

try {
throw;
} catch (...) {
std::cerr << "Caught exception\n";
}
}

The first exception is caught when an integer is thrown. The second
one isn't caught.

I just need to capture an exception because of a possible error in a
constructor (so I can't pass back an error code). I don't need to send
any information in the exception, so I was just using throw without any
arguments. Looks like I'll need to send something just so it works
unless I'm doing something wrong.

3. Debugger doesnt catch exceptions in timer code

4. my code doesnt execute to the end of the function, and doesnt return any error...

5. VBA Code - if file doesnt exist move to next file

6. How do i copy a active sheet to a new sheet with code and everything

7. Strange RPCSS activity caught by File Monitor

8. SocketException from code not caught in try catch or Application_Error

9. SocketException from code not caught in try catch or Application_E

10. Performance Monitor File Copy and Rename File

11. BSOD errors; file copy errors; everything under the sun

12. File Server Migrator 1.0 - Copy local users, groups and everything else other copiers won't!

13. my site doesnt publish even though everything looks right and

14. my site doesnt publish even though everything looks right and i a.

15. Y doesnt everything work