473,468 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I/O handles can't be released

LBT
I have a window service written in VB.NET to scan directory and process file.
During directory scanning (scheduled by timer using
System.IO.Directory.GetFiles method), I can observe that the column "Handles"
in "Task Manager" will increase gradually but will be dropped after a short
while.

But when CPU is busy (reach 100%), the number specified by "Handles"
increases continuously until I have to manually stop the window service or
the server will be run out of resources. During this period of time, the "VM
Size" increases faster than "Mem Usage". Some readings of the window service
I grabbed from "Task Manager" are shown as follows:

CPU - 40%
Mem Usage - 66, 180K
VM Size - 175, 380K
Handles - 190, 172
Thread - 62

Any idea why the I/O handles cannot be released but instead grows
continually and tremendously?
Directory.GetFiles method will tentatively cause this problem?
Why the VM Size is increased faster than Mem Usage in this case?
What workaround can be added to my code to handle the problem?

Thanks
Nov 21 '05 #1
5 1487
Hi,

The garbage collector hasnt taken out the garbage. Make sure you
dispose of any unused variables. Call gc.collect to force the framework to
take out the garbage.

Ken
-------------------
"LBT" <LB*@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
I have a window service written in VB.NET to scan directory and process
file.
During directory scanning (scheduled by timer using
System.IO.Directory.GetFiles method), I can observe that the column
"Handles"
in "Task Manager" will increase gradually but will be dropped after a short
while.

But when CPU is busy (reach 100%), the number specified by "Handles"
increases continuously until I have to manually stop the window service or
the server will be run out of resources. During this period of time, the "VM
Size" increases faster than "Mem Usage". Some readings of the window service
I grabbed from "Task Manager" are shown as follows:

CPU - 40%
Mem Usage - 66, 180K
VM Size - 175, 380K
Handles - 190, 172
Thread - 62

Any idea why the I/O handles cannot be released but instead grows
continually and tremendously?
Directory.GetFiles method will tentatively cause this problem?
Why the VM Size is increased faster than Mem Usage in this case?
What workaround can be added to my code to handle the problem?

Thanks
Nov 21 '05 #2
LBT
Thanks for the reply

I have a timer which elapses every minute and it will call GC.Collect to
execute. But seem this has no effect to release the I/O handles and memory.

My code on directory scanning like this:

-----------------------------------------------------------------------------------------------
Dim fileEntries As String() = Directory.GetFiles(targetDir)
Dim fileEntry As String
Dim DateTime As String
Dim FileName As String
Dim alFileName As New ArrayList()

'************************************************* *
' Process the list of files found in the directory
'************************************************* *
For Each fileEntry In fileEntries
Dim fi As New FileInfo(fileEntry)
' Format File CreationTime
DateTime = Format(Directory.GetCreationTime(fileEntry), "dd/MM/yyyy
hh:mm:ss fffffff")

' The file is txt file
If fi.Extension.CompareTo(".txt") = 0 Then
' If not yet added in ArrayList, add [DateTime & File Path]
If Not alFileName.Contains(DateTime & ";" & fileEntry.ToString) Then
alFileName.Add(DateTime & ";" & fileEntry.ToString)
End If

txtFound = True

' File is OTHER than txt Extension, Move to ERROR folder ***
ElseIf fi.Extension.CompareTo(".txt") <> 0 Then
If (File.Exists(fileEntry)) Then
cf.MoveFile(fileEntry.ToString, Mid(fileEntry,
fileEntry.LastIndexOf("\") + 2), "Error", 0, type)
End If
End If
fi = Nothing
Nex
------------------------------------------------------------------------------------------------

How to force the I/O handles to release? Or can I add code to force I/O
handles to release after its attempt to get files is failed within a
predefined time?

Seem that the I/O handles keep on increase because my timer elapsed event is
continuously trigger the directory scanning action. With the previous I/O
handles still try to scan the directory (CPU busy has caused the delay to the
directory scanning [correct me if I'm wrong]), the I/O handles will be
increased and lead to memory leak. How am I suppose to do to control for this?
"Ken Tucker [MVP]" wrote:
Hi,

The garbage collector hasnt taken out the garbage. Make sure you
dispose of any unused variables. Call gc.collect to force the framework to
take out the garbage.

Ken
-------------------
"LBT" <LB*@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
I have a window service written in VB.NET to scan directory and process
file.
During directory scanning (scheduled by timer using
System.IO.Directory.GetFiles method), I can observe that the column
"Handles"
in "Task Manager" will increase gradually but will be dropped after a short
while.

But when CPU is busy (reach 100%), the number specified by "Handles"
increases continuously until I have to manually stop the window service or
the server will be run out of resources. During this period of time, the "VM
Size" increases faster than "Mem Usage". Some readings of the window service
I grabbed from "Task Manager" are shown as follows:

CPU - 40%
Mem Usage - 66, 180K
VM Size - 175, 380K
Handles - 190, 172
Thread - 62

Any idea why the I/O handles cannot be released but instead grows
continually and tremendously?
Directory.GetFiles method will tentatively cause this problem?
Why the VM Size is increased faster than Mem Usage in this case?
What workaround can be added to my code to handle the problem?

Thanks

Nov 21 '05 #3

"LBT" <LB*@discussions.microsoft.com> wrote
For Each fileEntry In fileEntries
Dim fi As New FileInfo(fileEntry)

Because you are creating a new object for each iteration:

The first question I would ask is; why are you using methods of
the FileInfo class, instead of static methods of the File class?

LFS

Nov 21 '05 #4
LBT
Last time I just get the idea from somewhere else.

If FileInfo is not suitable to be used for my case, may I know the
workaround using File Class? What is the benefit of using static methods vs
instance methods (FileInfo class) for my case? FileInfo class will
potentially cause more and more I/O handled to be created and never be
released when CPU is busy? Would appreciated if some URLs of reference are
given :)

"Larry Serflaten" wrote:

"LBT" <LB*@discussions.microsoft.com> wrote
For Each fileEntry In fileEntries
Dim fi As New FileInfo(fileEntry)

Because you are creating a new object for each iteration:

The first question I would ask is; why are you using methods of
the FileInfo class, instead of static methods of the File class?

LFS

Nov 21 '05 #5

"LBT" <LB*@discussions.microsoft.com> wrote
Last time I just get the idea from somewhere else.

If FileInfo is not suitable to be used for my case, may I know the
workaround using File Class?

I got pointed to the File class from the documentation on the FileInfo
class. Really what you'd use is the Path.GetExtension function. That
would return the extension for you to make your comparisons. It
also will avoid creating a new object for every iteration. Why make
the GC work, when you can (easily) avoid it?

HTH
LFS


Nov 21 '05 #6

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

Similar topics

1
by: J. Dudgeon | last post by:
Hello, I've written a server that acts as a proxy between the PC and the mainframe worlds. This server service is writting in C# w/.NET 1.1. The service is TCP/IP based and makes heavy use of...
6
by: Mark Escandon | last post by:
I'VE POSTED THIS BEFORE BUT I STILL HAVE THE PROBLEM- I wrote a database client with vb.net. It runs fine for about a week and then I loose all connectivity. Windows NT displays a system error...
3
by: gmtonyhoyt | last post by:
Okay, this one's a tough one for me to explain so this might take a few e-mails to get the idea across. Here's what I got though. I have this application running on a Sun/Solaris machine,...
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
6
by: antonyliu2002 | last post by:
Right now I put my VB code in the aspx pages. I would prefer to use codebehind, especially many of my VB functions may be shared across multiple aspx pages. I've tried a few pages with...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.