473,657 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service - Out of memory

I have created a windows service using vb.net which uses a filesystemwatch er
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(ByV al path As String, ByVal filename As
String)

Dim asr As AppSettingsRead er = New AppSettingsRead er

Dim sRemoteDirector y As String = CType(asr.GetVa lue("RemoteDire ctory",
GetType(String) ), String)

Dim sBackupDirector y As String = CType(asr.GetVa lue("BackupDire ctory",
GetType(String) ), String)

' Dim img As Image = ImageFromFile(p ath)

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

//

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

Return Image.FromStrea m(fs)

fs.Dispose()

//

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

Dim imgFormat As Imaging.ImageFo rmat = GetImageFormat( path)

'Maintain aspect ratio

Dim scale As Double = 0

Dim width, height As Integer

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

height = CType(asr.GetVa lue("ImageHeigh t", 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(filen ame)

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

bmp.Save(sRemot ePath, imgFormat)

bmp.Dispose()

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

' File.Copy(path, sBackupPath, True)

' File.Delete(pat h)

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

The call stack is as follows

[External Code]
GeminiPictureSe rvice.exe!Gemin iPictureService .GeneralRoutine s.ResizeImage(s tring
path = "C:\\Pictur e Test 1\\IMGP0353.JPG ", string filename =
"IMGP0353.J PG") Line 18 + 0x9 bytes Unknown

GeminiPictureSe rvice.exe!Gemin iPictureService .GeminiPictureS ervice.fswGemin i_Created(objec t
sender = {System.IO.File SystemWatcher}, System.IO.FileS ystemEventArgs e =
{System.IO.File SystemEventArgs }) Line 42 + 0x20 bytes Unknown
[External Code]
Exception

- $exception {System.OutOfMe moryException: Out of memory.
at System.Drawing. Image.FromFile( String filename, Boolean
useEmbeddedColo rManagement)
at System.Drawing. Image.FromFile( String filename)
at GeminiPictureSe rvice.GeneralRo utines.ResizeIm age(String path, String
filename)
at GeminiPictureSe rvice.GeminiPic tureService.fsw Gemini_Created( Object
sender, FileSystemEvent Args e)
at System.IO.FileS ystemWatcher.On Created(FileSys temEventArgs e)
at System.IO.FileS ystemWatcher.No tifyFileSystemE ventArgs(Int32 action,
String name)
at System.IO.FileS ystemWatcher.Co mpletionStatusC hanged(UInt32 errorCode,
UInt32 numBytes, NativeOverlappe d* overlappedPoint er)
at
System.Threadin g._IOCompletion Callback.Perfor mIOCompletionCa llback(UInt32
errorCode, UInt32 numBytes, NativeOverlappe d* pOVERLAP)} System.Exceptio n
{System.OutOfMe moryException}

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 4756
On Fri, 30 Jun 2006 12:16:20 +0100, Rocky wrote:
Exception

- $exception {System.OutOfMe moryException: Out of memory.
at System.Drawing. Image.FromFile( String filename, Boolean
useEmbeddedColo rManagement)
at System.Drawing. Image.FromFile( String filename)


GDI+ tends to throw OutOfMemoryExce ptions 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 OutOfMemoryExce ption 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
565
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 installed on Windows 2003 Server, the application works well, and the COM object can be called just as it's meant to be. The service is however running under the IWAM account (I know strange account to run a service). However, after a while (from...
8
15965
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 usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb. I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a...
1
1931
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
2814
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 web service. The web service will be calling the windows service to get information relating to the printers installed on this machine. J
3
4786
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 ServiceController to check that the Service on the specified machine is running, can I get the DataSet that is held within the Service? Is it possible to create Properties or have a function that returns the DataSet? Kind Regards,
2
1813
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' along with a large class that I wrote that actually does all the work. The Service Manager app uses .NET remoting to get info into/back from the service. I have a couple of questions that I need info on before I complete this service:
8
7599
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 wee hours of the morning). From the time the service starts to the first time it hits the database its memory consumption is about 6.9MB which is a figure I can live with. However, after it hits the database for the first time its memory jumps to...
7
4030
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 creates a bunch of PDFs with Crystal Reports. Another service is a remote object which serves as our data access component -- basically it just executes stored procedures and returns datasets. If you watch the services in task manager, you can...
1
2218
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 start several instances of the same application, like multiple Windows Calculators for instance. We are experiencing difficulties starting applications after a certain number have been started. We changed our app to work as a Console...
3
7046
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 run application remotely and retrieve grid and form data in some way without accessing directly to database server? Web Services is being used for this purpose I think, Which methods must be used for this ?
0
8392
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
8825
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...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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...
1
6163
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
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.