473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Copy program crashes

All,
Been trying to get a little program to work, and I think I'm really close,
but I'm afraid I need to be pointed in the right direction. The code below
will watch a directory for files created. If a file is created, it will
copy it off to another directory. This even works if a bunch of files are
created all at once, but after a few copies, the program dies for some
reason. I suspect it's an IO issue, but I wanted to check with the experts
here. Any ideas?

Imports System.ServiceProcess
Imports System.Threading

Public Class Service1
Inherits System.ServiceProcess.ServiceBase
Dim DestDirectory As String
Dim WatchDirectory As String
Dim SourceFilePath As String
Dim SourceFileName As String
Dim MyQueue As New Queue
Dim MyRetValue As New Queue
Private CopyF As New Thread(New System.Threading.ThreadStart(AddressOf
CopyFile))
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(ServicesToRu n)
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()
CopyF.Start()

End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Watchservice.Abort()
CopyF.Abort()
End Sub
Private Sub StartMonitor()

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
'result = Nothing
AddHandler watcher.Created, AddressOf logchange
'Dim SourceFileNameObject As IO.WaitForChangedResult
'Dim SourceFileName As String
'SourceFileName = SourceFileNameObject.Name
'MsgBox(SourceFileName)
watcher.InternalBufferSize.Equals(4000960)
watcher.EnableRaisingEvents = True
'result =
watcher.WaitForChanged(System.IO.WatcherChangeType s.Created)

End Sub
Private Sub logchange(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Created Then
SourceFilePath = e.FullPath
SourceFileName = e.Name

'MsgBox(SourceFilePath)
'MsgBox(DestDirectory & "\" & SourceFileName)
'Add files to queue to be picked off in a new sub below
MyQueue.Enqueue(SourceFilePath)
'MyRetValue = queue.Synchronized(MyQueue)
'MsgBox(MyQueue.Count)
End If
End Sub
Private Sub CopyFile()
Do
If MyQueue.Count 0 Then
'MsgBox("Starting to copy files hopefully")
'get files from the queue, and copy them to destination path
Dim DestPath As String
Dim DQedSrceFilePath As String
DQedSrceFilePath = MyQueue.Dequeue()
DestPath = DestDirectory & "\" & SourceFileName
My.Computer.FileSystem.CopyFile(DQedSrceFilePath, DestPath)
End If
Loop
End Sub
End Class
Apr 2 '07 #1
4 4626
On Apr 1, 9:24 pm, "TwistedPair" <twistedp...@mail.comwrote:
created all at once, but after a few copies, the program dies for some
reason. I suspect it's an IO issue, but I wanted to check with the experts
What does this mean? Are you getting an exception? If so, what is
it? Without knowing what the exception is, it will be very difficult
to help you.

Chris

Apr 2 '07 #2
I know, that's the problem. It just dies. I didn't think to check the
event log until now though, and turns out that the error does show there:

EventType clr20r3, P1 watchdirservice.exe, P2 1.0.0.0, P3 46106804, P4
mscorlib, P5 2.0.0.0, P6 4333ab80, P7 32f8, P8 254, P9
system.io.ioexception, P10 NIL.

So it looks like the problem is IO related after all?
"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
On Apr 1, 9:24 pm, "TwistedPair" <twistedp...@mail.comwrote:
>created all at once, but after a few copies, the program dies for some
reason. I suspect it's an IO issue, but I wanted to check with the
experts

What does this mean? Are you getting an exception? If so, what is
it? Without knowing what the exception is, it will be very difficult
to help you.

Chris

Apr 2 '07 #3
On Apr 2, 11:20 am, "TwistedPair" <twistedp...@mail.comwrote:
I know, that's the problem. It just dies. I didn't think to check the
event log until now though, and turns out that the error does show there:

EventType clr20r3, P1 watchdirservice.exe, P2 1.0.0.0, P3 46106804, P4
mscorlib, P5 2.0.0.0, P6 4333ab80, P7 32f8, P8 254, P9
system.io.ioexception, P10 NIL.

So it looks like the problem is IO related after all?

"Chris Dunaway" <dunaw...@gmail.comwrote in message

news:11**********************@b75g2000hsg.googlegr oups.com...
On Apr 1, 9:24 pm, "TwistedPair" <twistedp...@mail.comwrote:
created all at once, but after a few copies, the program dies for some
reason. I suspect it's an IO issue, but I wanted to check with the
experts
What does this mean? Are you getting an exception? If so, what is
it? Without knowing what the exception is, it will be very difficult
to help you.
Chris
Well, that's something, but even that doesn't help very much. A
better way to get the exception is to add a global exception handler
either by putting a try catch around the code in your main method or
by handling the AppDoman.UnhandledException event. Then you can log
the exception to a file and find out exactly what and where it is.

Good luck

Chris

Apr 2 '07 #4
Got it, thanks Chris, I'll give that a try. (-:

"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
On Apr 2, 11:20 am, "TwistedPair" <twistedp...@mail.comwrote:
>I know, that's the problem. It just dies. I didn't think to check the
event log until now though, and turns out that the error does show there:

EventType clr20r3, P1 watchdirservice.exe, P2 1.0.0.0, P3 46106804, P4
mscorlib, P5 2.0.0.0, P6 4333ab80, P7 32f8, P8 254, P9
system.io.ioexception, P10 NIL.

So it looks like the problem is IO related after all?

"Chris Dunaway" <dunaw...@gmail.comwrote in message

news:11**********************@b75g2000hsg.googleg roups.com...
On Apr 1, 9:24 pm, "TwistedPair" <twistedp...@mail.comwrote:
created all at once, but after a few copies, the program dies for some
reason. I suspect it's an IO issue, but I wanted to check with the
experts
What does this mean? Are you getting an exception? If so, what is
it? Without knowing what the exception is, it will be very difficult
to help you.
Chris

Well, that's something, but even that doesn't help very much. A
better way to get the exception is to add a global exception handler
either by putting a try catch around the code in your main method or
by handling the AppDoman.UnhandledException event. Then you can log
the exception to a file and find out exactly what and where it is.

Good luck

Chris

Apr 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: spoc | last post by:
I have been using memcpy to copy one class to another of the same type. There are reasons why I had to do this bug am getting some odd crashes and maybe I'm doing something dodgy copying classes...
8
by: Paul Bromley | last post by:
I am about to release the second version of a program that I started writing 12 months ago. The first version worked fine on 98 upwards. This version seems to crash on Windows 98. I realise that...
2
by: manuthomas23 | last post by:
Here is the code: #ifndef M3DCAMERA__H__ #define M3DCAMERA__H__ class M3DEngine; /** Micro3D Camera class. */
9
by: muzmail | last post by:
I have declared a copy constructor for a template class in a Visual C++ project but for some reason the compiler ignores it. I can put syntax errors in the copy constructor and the compiler ignores...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
27
by: JoeC | last post by:
I am still working on my game and my program is getting better. Most of what I want to works. I think I am having trouble with copy constructor. Basically I want it to copy the gdata array. My...
6
by: popone | last post by:
Hi All, I've developed a program that seems to crash randomly, from what I can tell it's after some user action. If it just sat there, it wouldn't crash. It's not an exception either, it's the...
41
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as...
2
by: jaddle | last post by:
I program I'm writing crashes when it exits with a segfault. I'm runnning under linux. Using gdb, i see that the crash happens after the last line of main(), which is just a return(EXIT_SUCCESS); If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.