I have a zipfile that I am trying to close because the file is corrupted and
I get an error on it:
Exception of type 'java.util.zip.ZipException' was thrown
So I handle the error and finally try to close the error. But there appears
to be some time of timing issue.
ZipFile zipfile = null;
try
{
zipfile = new ZipFile(zipFileName);
}
catch(Exception exc)
{
throw new Exception("File: " + zipFileName + " Corrupted",
exc);
}
finally
{
if (zipfile != null)
{
zipfile.close();
}
}
In the above code, I get the exception and get the if (zipfile != null) test
and this is where it all takes a different path depending on how long I
take.
If the "if" test was not there, I would get an error saying that the object
does not exist and I will then get an error saying that I can't move it
because it is in use. If I trace through it, it also doesn't get to the
zipfile.close(), but it allows me to move it so it is obviously not in use.
How can I handle this? I can't use a "using" clause as it is not
IDisposable.
It seems to close if I step through which seems to allow it to get released.
Thanks,
Tom 5 1478
I found the problem (and the solution). The problem was that the
constructor is opening the .zip file passed and if it determines that the
file has a problem, it does an IOException but never closes the stream.
You have to wait until the Garbage Collector realizes that this object (the
..zip file) now has nothing pointing at it and closes it. But the problem is
you would never know when it was done.
So you do a System.GC.Collect() to force the Garbage Collector to do its
thing now. Now, there is no access problem.
It was really a couple line change:
ZipFile zipfile = null;
try
{
zipfile = new ZipFile(zipFileName);
}
catch(Exception exc)
{
throw new Exception("File: " + zipFileName + " Corrupted",
exc);
}
finally
{
if (zipfile != null)
{
zipfile.close();
}
else
System.GC.Collect();
}
Works perfectly.
Tom
"tshad" <tf*@dslextreme.comwrote in message
news:uy*************@TK2MSFTNGP06.phx.gbl...
>I have a zipfile that I am trying to close because the file is corrupted and I get an error on it:
Exception of type 'java.util.zip.ZipException' was thrown
So I handle the error and finally try to close the error. But there
appears to be some time of timing issue.
ZipFile zipfile = null;
try
{
zipfile = new ZipFile(zipFileName);
}
catch(Exception exc)
{
throw new Exception("File: " + zipFileName + " Corrupted",
exc);
}
finally
{
if (zipfile != null)
{
zipfile.close();
}
}
In the above code, I get the exception and get the if (zipfile != null)
test and this is where it all takes a different path depending on how long
I take.
If the "if" test was not there, I would get an error saying that the
object does not exist and I will then get an error saying that I can't
move it because it is in use. If I trace through it, it also doesn't get
to the zipfile.close(), but it allows me to move it so it is obviously not
in use.
How can I handle this? I can't use a "using" clause as it is not
IDisposable.
It seems to close if I step through which seems to allow it to get
released.
Thanks,
Tom
On Wed, 01 Oct 2008 18:00:00 -0700, tshad <tf*@dslextreme.comwrote:
I found the problem (and the solution). The problem was that the
constructor is opening the .zip file passed and if it determines that the
file has a problem, it does an IOException but never closes the stream.
You have to wait until the Garbage Collector realizes that this object
(the
.zip file) now has nothing pointing at it and closes it. But the
problem is
you would never know when it was done.
So you do a System.GC.Collect() to force the Garbage Collector to do its
thing now. Now, there is no access problem.
It was really a couple line change:
[...]
Works perfectly.
Well, except for the fact that you're calling a method that you should
never need to call.
From your post, it looks like you're trying to use some Java library thing
from C#. My advice would be to ditch the buggy library. If they got that
wrong, who knows what other bugs you're going to run into.
Pete
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Wed, 01 Oct 2008 18:00:00 -0700, tshad <tf*@dslextreme.comwrote:
>I found the problem (and the solution). The problem was that the constructor is opening the .zip file passed and if it determines that the file has a problem, it does an IOException but never closes the stream.
You have to wait until the Garbage Collector realizes that this object (the .zip file) now has nothing pointing at it and closes it. But the problem is you would never know when it was done.
So you do a System.GC.Collect() to force the Garbage Collector to do its thing now. Now, there is no access problem.
It was really a couple line change:
[...]
Works perfectly.
Well, except for the fact that you're calling a method that you should
never need to call.
From your post, it looks like you're trying to use some Java library thing
from C#. My advice would be to ditch the buggy library. If they got that
wrong, who knows what other bugs you're going to run into.
It is a Java library that is part of MS libraries. You have to reference
it, but it works well except for this problem. It was the only library I
could find that dealt with zip files and is pretty simple to use.
Thanks,
Tom
>
Pete
On Oct 2, 4:01*pm, "tshad" <t...@dslextreme.comwrote:
Well, except for the fact that you're calling a method that you should
never need to call.
From your post, it looks like you're trying to use some Java library thing
fromC#. *My advice would be to ditch the buggy library. *If they got that
wrong, who knows what other bugs you're going to run into.
It is a Java library that is part of MS libraries. *You have to reference
it, but it works well except for this problem. *It was the only libraryI
could find that dealt withzipfiles and is pretty simple to use.
Tom, have you checked out DotNetZip? It's free, much simpler to use,
(yes, it implements IDisposable), and doesn't require you to call
GC.Collect(). http://www.codeplex.com/DotNetZip .
"Cheeso" <dp******@mailinator.comwrote in message
news:49**********************************@k36g2000 pri.googlegroups.com...
On Oct 2, 4:01 pm, "tshad" <t...@dslextreme.comwrote:
Well, except for the fact that you're calling a method that you should
never need to call.
From your post, it looks like you're trying to use some Java library
thing
fromC#. My advice would be to ditch the buggy library. If they got that
wrong, who knows what other bugs you're going to run into.
It is a Java library that is part of MS libraries. You have to reference
it, but it works well except for this problem. It was the only library I
could find that dealt withzipfiles and is pretty simple to use.
Tom, have you checked out DotNetZip? It's free, much simpler to use, (yes, it implements IDisposable), and doesn't require you to call GC.Collect(). http://www.codeplex.com/DotNetZip .
I probably will look at this for my next project.
I already have this one working and this has been my only problem with it.
When I was looking before for how to handle zip files I don't think I saw
this one or probably would have used it. This was part of the .net
libraries (even though it was in Java) and did the job when I needed it.
I agree, I would rather not have to call GC.Collect(). But it isn't the
worse thing that could happen, I suppose.
Thanks,
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christopher W. Douglas |
last post by:
I am working on a project in VB.NET using Visual Studio.NET 2003. I use
dialog windows to get user information, and throw exceptions when there are
user errors, such as leaving a field blank or...
|
by: Steve Jorgensen |
last post by:
Hi all,
I had just participating in a small thread here about when to set recordset
variables to Nothing when I ran into an interesting case in my own code that
highlighted the need for a...
|
by: W Akthar |
last post by:
Hi
I am trying to create a windows service which queries SQL
Server on timed intervals and depending on the results
send appointments to Outlook.
The problem lies when I try to create an...
|
by: Lee Jackson |
last post by:
Whats the difference between the following in terms of how the CLR
allocates and garbage collects? Which is better in terms of memory
usage/performance?
a)
foreach (string strURL in...
|
by: TZ |
last post by:
I have two classes, UIHousehold and WIZEditHousehold (both are
winforms).
UIHousehold creates and shows the WIZEditHousehold (WIZEditHousehold
can't be modal, so UIHousehold doesn't know when...
|
by: Patreek |
last post by:
Hi,
On the line where I'm assigning RecordCount to be the value of my output
parameter, I'm getting the generic "Object reference not set to an instance
of an object" error. I've isolated it...
|
by: Dave |
last post by:
I'm having trouble understanding dispose. I set up a class that, among
other things, displays the time in a status bar panel. It does this by
starting a thread. I create an instance of this...
|
by: Brian Bischof |
last post by:
In my Win app I found that using the SMTP object doesn't release resources after closing the application. During testing I have to open and close the app many times and I found that after about three...
|
by: cedgington |
last post by:
I wanted to take advantage of the large set of functionality offered by
the framework, so for my latest project I'm using managed C++ with .NET
v2. I'm using the gcnew operator in two different...
|
by: Jamey Shuemaker |
last post by:
I've seen multiple threads (several in the last 6 months or so) on this
topic, but I wanted to clarify my practices. I understand the need for
cleaning object variables by setting them to Nothing...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |