473,387 Members | 1,863 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,387 software developers and data experts.

Windows Service - Out of memory

I have created a windows service using vb.net which uses a filesystemwatcher
to monitoe files in a specifc directory, if images are added to the
directory they are resized and saved in a remote directory. The original
file is then backed up and deleted from the image directory.

The code is as follows

Friend Shared Sub ResizeImage(ByVal path As String, ByVal filename As
String)

Dim asr As AppSettingsReader = New AppSettingsReader

Dim sRemoteDirectory As String = CType(asr.GetValue("RemoteDirectory",
GetType(String)), String)

Dim sBackupDirectory As String = CType(asr.GetValue("BackupDirectory",
GetType(String)), String)

' Dim img As Image = ImageFromFile(path)

(This was put in as an alternative but produced the same problem

//

Dim fs As FileStream = New FileStream(filename, FileMode.Open,
FileAccess.Read)

Return Image.FromStream(fs)

fs.Dispose()

//

Dim img As Image = Image.FromFile(path) << It fails here

Dim imgFormat As Imaging.ImageFormat = GetImageFormat(path)

'Maintain aspect ratio

Dim scale As Double = 0

Dim width, height As Integer

width = CType(asr.GetValue("ImageWidth", GetType(String)), Integer)

height = CType(asr.GetValue("ImageHeight", GetType(String)), Integer)

'Caters for the user specifying 0 for either width or height

If width = 0 Then

width = 1

ElseIf height = 0 Then

height = 1

End If

If img.Height < img.Width Then

scale = width / img.Width

Else

scale = height / img.Height

End If

Dim newwidth As Integer = CInt(scale * img.Width)

Dim newheight As Integer = CInt(scale * img.Height)

Dim bmp As New Bitmap(img, newwidth, newheight)

img.Dispose()

'Add a log entry

' SaveToLog(filename)

Dim sRemotePath As String = String.Format("{0}\{1}", sRemoteDirectory,
filename)

bmp.Save(sRemotePath, imgFormat)

bmp.Dispose()

' Dim sBackupPath As String = String.Format("{0}\{1}", sBackupDirectory,
filename)

' File.Copy(path, sBackupPath, True)

' File.Delete(path)

Whether I copy a couple of images or lots, the error is always the same

The call stack is as follows

[External Code]
GeminiPictureService.exe!GeminiPictureService.Gene ralRoutines.ResizeImage(string
path = "C:\\Picture Test 1\\IMGP0353.JPG", string filename =
"IMGP0353.JPG") Line 18 + 0x9 bytes Unknown

GeminiPictureService.exe!GeminiPictureService.Gemi niPictureService.fswGemini_Created(object
sender = {System.IO.FileSystemWatcher}, System.IO.FileSystemEventArgs e =
{System.IO.FileSystemEventArgs}) Line 42 + 0x20 bytes Unknown
[External Code]
Exception

- $exception {System.OutOfMemoryException: Out of memory.
at System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at GeminiPictureService.GeneralRoutines.ResizeImage(S tring path, String
filename)
at GeminiPictureService.GeminiPictureService.fswGemin i_Created(Object
sender, FileSystemEventArgs e)
at System.IO.FileSystemWatcher.OnCreated(FileSystemEv entArgs e)
at System.IO.FileSystemWatcher.NotifyFileSystemEventA rgs(Int32 action,
String name)
at System.IO.FileSystemWatcher.CompletionStatusChange d(UInt32 errorCode,
UInt32 numBytes, NativeOverlapped* overlappedPointer)
at
System.Threading._IOCompletionCallback.PerformIOCo mpletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)} System.Exception
{System.OutOfMemoryException}

Memory - I checked the process and the memory usage spiked from 8,000 to
(40-46k), it stayed at around 40k before giving an exception

System Pentium 1.8GHz 1GB Ram Windows XP Pro SP2

Thanks for any help in advance
Jun 30 '06 #1
1 4737
On Fri, 30 Jun 2006 12:16:20 +0100, Rocky wrote:
Exception

- $exception {System.OutOfMemoryException: Out of memory.
at System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)


GDI+ tends to throw OutOfMemoryExceptions whenever something goes wrong
event if that's got nothing to do with a memory problem. In the case of
Image.FromFile(), I *think* that you might get an OutOfMemoryException if
the image is corrupted or has an unsuported format. I would investigate
this first.
Jun 30 '06 #2

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

Similar topics

0
by: Martijn Remmen | last post by:
I have developed a service which exposes a COM object. This service is running perfect on Windows 2000 Server and Windows 2000 Professional under the SYSTEM account. When the service is...
8
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem...
1
by: sidd | last post by:
Hi all, how do i exit out(unload) of a windows service in case of an error. so i have a code block as follows try { } catch(exception ex) { //log to event log
2
by: J | last post by:
Hello, What is the best/easiest way to setup interprocess communication between a windows service and a webservice? The windows service will be running on the same machine that is hosting the...
3
by: Steve Amey | last post by:
Hi all Is it possible to retrieve data from a Windows Service? Let's say I have a service that contains code in the OnStart method that creates a DataSet, from a client application I'm using a...
2
by: Tom Simpson | last post by:
I have set up a Windows service in VB.NET, and created a 'Service Manager' Windows Forms app that can 'get' information from that service. The service consists of the basic service 'framework'...
8
by: nautonnier | last post by:
I know my problem has been discussed ad nauseum but I still don't get it so please bear with me. I have written a service which performs some work against a database once a day (usually in the...
7
by: HeatherS | last post by:
We are having issues with our windows services using memory and never releasing it. We have one service that has a file watcher which takes an xml file, inserts some records into a database, and...
1
by: mikelujan | last post by:
Hi, Our application starts an external application using System.Diagnostics.Process class and the Start() method, as per code snippet below. This application run as a Windows service, and must...
3
by: Sylvie | last post by:
My Windows Application has two forms, one form contains a grid (lets say Stock Listing), and the other is a form of one stock, contains some edit boxes for one stock's fields.. Is it possible to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...
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
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...

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.