By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

problem when using windows services

P: n/a
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows Application,
does not work while I run it with Windows services.
In my Windows application I am able to zip the whole 900Mb without any
problems,
but in my windows services I am not able to zip the whole 900Mb.
In Windows Services it throws an error :SystemOutOfMemoryException
I am trying to zip all image files, example: idx,fim,rim
Below is the code I am using:

Please help me to find the solution to run this code properly in windows
services as well.

using Xceed.Compression;

using Xceed.FileSystem;

using Xceed.Zip;

Xceed.Zip.Licenser.LicenseKey = "ZINxx-xxxxx-xxxxx-xxxx";

public int MakeZipFile(string zipFileName, string[] filesToComp)
{
int retVal = 0;
DiskFolder tempFolder = new DiskFolder();
try
{
ZipArchive zip = new ZipArchive( new DiskFile( zipFileName ) );
zip.TempFolder = tempFolder;
try
{
zip.BeginUpdate();
foreach( string file in filesToComp )
{
DiskFile fileToZip = new DiskFile( file );
fileToZip.CopyTo( zip, true );
++retVal;
}
}
finally
{
zip.EndUpdate();
}
}

catch(Exception exec)
{
throw new ZipException(exec.Message);
}
finally
{
}
return retVal;
}
}

}

// Windows Services --- main part of execution

string zipfilepath="C:\\temp\\pollNew.zip"; // all my image files will be
zipped in pollnew.zip
string[] pFiles=new string[7]; // pFiles contains all files
that I want to zip
pFiles[0]="D:\\New\\121807\\00007069.FCI";
pFiles[1]="D:\\New\\121807\\00007069.FI2";
pFiles[2]="D:\\New\\121807\\00007069.FIM";
pFiles[3]="D:\\New\\121807\\00007069.IDX";
pFiles[4]="D:\\New\\121807\\00007069.RCI";
pFiles[5]="D:\\New\\121807\\00007069.RI2";
pFiles[6]="D:\\New\\121807\\00007069.RIM";
MakeZipFile(string zipfilepath, string[] pFiles) // calling MakeZipFile
Function Here
Dec 28 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"vishruth" <vi******@discussions.microsoft.comwrote in message
news:A5**********************************@microsof t.com...
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows Application,
does not work while I run it with Windows services.
In my Windows application I am able to zip the whole 900Mb without any
problems,
but in my windows services I am not able to zip the whole 900Mb.
In Windows Services it throws an error :SystemOutOfMemoryException
I am trying to zip all image files, example: idx,fim,rim
Below is the code I am using:

Please help me to find the solution to run this code properly in windows
services as well.

using Xceed.Compression;

using Xceed.FileSystem;

using Xceed.Zip;

Xceed.Zip.Licenser.LicenseKey = "ZINxx-xxxxx-xxxxx-xxxx";

public int MakeZipFile(string zipFileName, string[] filesToComp)
{
int retVal = 0;
DiskFolder tempFolder = new DiskFolder();
try
{
ZipArchive zip = new ZipArchive( new DiskFile( zipFileName ) );
zip.TempFolder = tempFolder;
try
{
zip.BeginUpdate();
foreach( string file in filesToComp )
{
DiskFile fileToZip = new DiskFile( file );
fileToZip.CopyTo( zip, true );
++retVal;
}
}
finally
{
zip.EndUpdate();
}
}

catch(Exception exec)
{
throw new ZipException(exec.Message);
}
finally
{
}
return retVal;
}
}

}

// Windows Services --- main part of execution

string zipfilepath="C:\\temp\\pollNew.zip"; // all my image files will
be
zipped in pollnew.zip
string[] pFiles=new string[7]; // pFiles contains all files
that I want to zip
pFiles[0]="D:\\New\\121807\\00007069.FCI";
pFiles[1]="D:\\New\\121807\\00007069.FI2";
pFiles[2]="D:\\New\\121807\\00007069.FIM";
pFiles[3]="D:\\New\\121807\\00007069.IDX";
pFiles[4]="D:\\New\\121807\\00007069.RCI";
pFiles[5]="D:\\New\\121807\\00007069.RI2";
pFiles[6]="D:\\New\\121807\\00007069.RIM";
MakeZipFile(string zipfilepath, string[] pFiles) // calling MakeZipFile
Function Here


Don't ever assume you have that huge block of free memory available in a
32-bit process. The fact that it works in a Windows program (say you were
lucky) doesn't mean it will work in another kind of application, note that
it's even possible that it will work all the time in your Windows
application one small change can easily spoil the party. If you need to make
sure that your memory demand as a chance to succeed, you'll have to
instantiate the MemoryFailPoint class from System.Runtime (assumes V2 of the
framework) before you initiate the memory consuming operation. Of course
this will need you to know the exact amount of memory needed for the
operation to succeed.
That said, I'm not entirely clear on why you need to run this from a Windows
Service, people tend to think that everything needs to run in the background
without even thinking about the complexities that come with developing
Services.

Willy.

Dec 28 '07 #2

P: n/a
As Willy pointed out, perhaps you do not need a Windows Service. If what you
need to do is make regular backups of images into a zip file, why not just
code it as a Console app and have Task Scheduler run it 1x a day?
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"vishruth" wrote:
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows Application,
does not work while I run it with Windows services.
In my Windows application I am able to zip the whole 900Mb without any
problems,
but in my windows services I am not able to zip the whole 900Mb.
In Windows Services it throws an error :SystemOutOfMemoryException
I am trying to zip all image files, example: idx,fim,rim
Below is the code I am using:

Please help me to find the solution to run this code properly in windows
services as well.

using Xceed.Compression;

using Xceed.FileSystem;

using Xceed.Zip;

Xceed.Zip.Licenser.LicenseKey = "ZINxx-xxxxx-xxxxx-xxxx";

public int MakeZipFile(string zipFileName, string[] filesToComp)
{
int retVal = 0;
DiskFolder tempFolder = new DiskFolder();
try
{
ZipArchive zip = new ZipArchive( new DiskFile( zipFileName ) );
zip.TempFolder = tempFolder;
try
{
zip.BeginUpdate();
foreach( string file in filesToComp )
{
DiskFile fileToZip = new DiskFile( file );
fileToZip.CopyTo( zip, true );
++retVal;
}
}
finally
{
zip.EndUpdate();
}
}

catch(Exception exec)
{
throw new ZipException(exec.Message);
}
finally
{
}
return retVal;
}
}

}

// Windows Services --- main part of execution

string zipfilepath="C:\\temp\\pollNew.zip"; // all my image files will be
zipped in pollnew.zip
string[] pFiles=new string[7]; // pFiles contains all files
that I want to zip
pFiles[0]="D:\\New\\121807\\00007069.FCI";
pFiles[1]="D:\\New\\121807\\00007069.FI2";
pFiles[2]="D:\\New\\121807\\00007069.FIM";
pFiles[3]="D:\\New\\121807\\00007069.IDX";
pFiles[4]="D:\\New\\121807\\00007069.RCI";
pFiles[5]="D:\\New\\121807\\00007069.RI2";
pFiles[6]="D:\\New\\121807\\00007069.RIM";
MakeZipFile(string zipfilepath, string[] pFiles) // calling MakeZipFile
Function Here
Dec 28 '07 #3

P: n/a
Thank you for your suggestion Willy, but at the same time, I am helpless,
that I have to run it only with windows services, as my company demands that.
Can u justify me that if the same code for zipping image files about 900mb
works with windows application,why doesnt it work with windows services.
But the same code in windows services works for lower MB files but if it
crosses say about 250 MB then I face this problem "System OutOfMemory
Exception".
If u can share your thoughts with me, I could pass on the same to the person
who assigned me this task.
It will be of gr8 help,then.

Thanks,
Vishruth

"vishruth" wrote:
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows Application,
does not work while I run it with Windows services.
In my Windows application I am able to zip the whole 900Mb without any
problems,
but in my windows services I am not able to zip the whole 900Mb.
In Windows Services it throws an error :SystemOutOfMemoryException
I am trying to zip all image files, example: idx,fim,rim
Below is the code I am using:

Please help me to find the solution to run this code properly in windows
services as well.

using Xceed.Compression;

using Xceed.FileSystem;

using Xceed.Zip;

Xceed.Zip.Licenser.LicenseKey = "ZINxx-xxxxx-xxxxx-xxxx";

public int MakeZipFile(string zipFileName, string[] filesToComp)
{
int retVal = 0;
DiskFolder tempFolder = new DiskFolder();
try
{
ZipArchive zip = new ZipArchive( new DiskFile( zipFileName ) );
zip.TempFolder = tempFolder;
try
{
zip.BeginUpdate();
foreach( string file in filesToComp )
{
DiskFile fileToZip = new DiskFile( file );
fileToZip.CopyTo( zip, true );
++retVal;
}
}
finally
{
zip.EndUpdate();
}
}

catch(Exception exec)
{
throw new ZipException(exec.Message);
}
finally
{
}
return retVal;
}
}

}

// Windows Services --- main part of execution

string zipfilepath="C:\\temp\\pollNew.zip"; // all my image files will be
zipped in pollnew.zip
string[] pFiles=new string[7]; // pFiles contains all files
that I want to zip
pFiles[0]="D:\\New\\121807\\00007069.FCI";
pFiles[1]="D:\\New\\121807\\00007069.FI2";
pFiles[2]="D:\\New\\121807\\00007069.FIM";
pFiles[3]="D:\\New\\121807\\00007069.IDX";
pFiles[4]="D:\\New\\121807\\00007069.RCI";
pFiles[5]="D:\\New\\121807\\00007069.RI2";
pFiles[6]="D:\\New\\121807\\00007069.RIM";
MakeZipFile(string zipfilepath, string[] pFiles) // calling MakeZipFile
Function Here
Dec 30 '07 #4

P: n/a
Is it possible that the zip library you are using is being
unnecessarily hungry here? I'm not familiar with the product (although
I recognise the name).

Off the wall, but have you tried the free but well-truested
sharpziplib? (and yes, I did notice that xceed sponsor icsharpcode).
(if you do, be sure to use a fixed size buffer; don't attempt to read
the entire source file at once).

Marc
Dec 30 '07 #5

P: n/a
For illustration, the following (using #ziplib) handles multi-hundred-
megabite files with a very small memory footprint - worth giving it a
whirl? (you might be able to further optimise it with some bespoke
buffer code).

using System;
using ICSharpCode.SharpZipLib.Zip;

class Program {
static void Main(string[] args) {
using (ZipFile zip = ZipFile.Create(args[0])) {
zip.BeginUpdate();
for(int i = 1; i <args.Length; i++) {
zip.Add(args[i]);
}
zip.CommitUpdate();
zip.Close();
}
}
}

Marc
Dec 30 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.