473,840 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
+ 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.Direc tory.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.GetFi les 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 1508
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*@discussion s.microsoft.com > wrote in message
news:22******** *************** ***********@mic rosoft.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.Direc tory.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.GetFi les 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.GetFi les(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(fileEn try)
' Format File CreationTime
DateTime = Format(Director y.GetCreationTi me(fileEntry), "dd/MM/yyyy
hh:mm:ss fffffff")

' The file is txt file
If fi.Extension.Co mpareTo(".txt") = 0 Then
' If not yet added in ArrayList, add [DateTime & File Path]
If Not alFileName.Cont ains(DateTime & ";" & fileEntry.ToStr ing) Then
alFileName.Add( DateTime & ";" & fileEntry.ToStr ing)
End If

txtFound = True

' File is OTHER than txt Extension, Move to ERROR folder ***
ElseIf fi.Extension.Co mpareTo(".txt") <> 0 Then
If (File.Exists(fi leEntry)) Then
cf.MoveFile(fil eEntry.ToString , Mid(fileEntry,
fileEntry.LastI ndexOf("\") + 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*@discussion s.microsoft.com > wrote in message
news:22******** *************** ***********@mic rosoft.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.Direc tory.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.GetFi les 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*@discussion s.microsoft.com > wrote
For Each fileEntry In fileEntries
Dim fi As New FileInfo(fileEn try)

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*@discussion s.microsoft.com > wrote
For Each fileEntry In fileEntries
Dim fi As New FileInfo(fileEn try)

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*@discussion s.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.GetExtensi on 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
434
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 sockets. The "client" to the service is a C# class library that also uses sockets. I've managed to get the performance of the service up to a decent speed but I've hit a strange problem.
6
1490
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 "no more internal File identifiers". I checked my program carefully to make sure that every odbc and streamreader is closed after I open them; However,Using process explorer, I can see that about 15 handles get added everytime I add a record. I...
3
1929
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, written in C, using the Sun Forte Developer 7 C 5.4 Compiler released a few years ago. Not exactly old but, you get the picture. Now, most if not all the file handles on this machine are most likely being used up by a secondary process and/or...
18
20201
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 are created and detected before writing completes and so I cannot read them until the file handle used in their creation has been released. This would be easy to get around with file renaming or other file locking mechanisms which I could use...
6
1566
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 codebehind by follwing some examples on the Web and they work just fine. However, I am scared away from codebehind by such extenstions as "Handles MyBase.Load", "Handles Button1.Click" and "Handles MyBase.Init" etc. which we seem to have to add to the...
0
9860
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10301
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9440
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7838
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.