473,668 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File locked problem in c#

Hi ng,

I have a very strange problem within my c# application:
One of the (background) Threads in my application is responsible for some
image processing tasks (like resizing, clipping, ..) on a list of files.
Therefore, some temporary files are created which should be deleted after
processing is finished.
This Thread is called several times. When I call it the first time,
everything's ok and no errors occur.
In the second call, I can observe very strange behaviour: I cannot delete
the temporary files created by this thread, but I'm sure that all image and
bitmap-objects are disposed after processing (with this method,which is, I
think more than should be necessary to release the file lock)
private static void DisposeImage(Im age image)

{
image.Dispose() ;
image = null;
GC.Collect();
}

Did anyone observe similar behaviour? Does anyone have any ideas what could
be the reason for this annoying file locks (e.g. error in threading or
whatever..)
Or, how could a workaround look like (which means how can I unlock a file
which was created by the same thread)

thx,
Albert

Jul 21 '05 #1
4 13630
You should always make sure that you close the streams used to load the
images as well.

Maybe that is the problem you're experiencing?

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Albert Greinöcker wrote:
Hi ng,

I have a very strange problem within my c# application:
One of the (background) Threads in my application is responsible for some
image processing tasks (like resizing, clipping, ..) on a list of files.
Therefore, some temporary files are created which should be deleted after
processing is finished.
This Thread is called several times. When I call it the first time,
everything's ok and no errors occur.
In the second call, I can observe very strange behaviour: I cannot delete
the temporary files created by this thread, but I'm sure that all image and
bitmap-objects are disposed after processing (with this method,which is, I
think more than should be necessary to release the file lock)
private static void DisposeImage(Im age image)

{
image.Dispose() ;
image = null;
GC.Collect();
}

Did anyone observe similar behaviour? Does anyone have any ideas what could
be the reason for this annoying file locks (e.g. error in threading or
whatever..)
Or, how could a workaround look like (which means how can I unlock a file
which was created by the same thread)

thx,
Albert

Jul 21 '05 #2
Thanks for your response...

The only two ways I'm opening the images is either

Image img = Image.FromFile( filePath);

Or with a copy constructor

Are in this case any additional closing steps necessary?

""Patrik Löwendahl [C# MVP]"" <pa************ *************** ***@home.se>
schrieb im Newsbeitrag news:OX******** ******@tk2msftn gp13.phx.gbl...
You should always make sure that you close the streams used to load the
images as well.

Maybe that is the problem you're experiencing?

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Albert Greinöcker wrote:
Hi ng,

I have a very strange problem within my c# application:
One of the (background) Threads in my application is responsible for some
image processing tasks (like resizing, clipping, ..) on a list of files.
Therefore, some temporary files are created which should be deleted after
processing is finished.
This Thread is called several times. When I call it the first time,
everything's ok and no errors occur.
In the second call, I can observe very strange behaviour: I cannot delete
the temporary files created by this thread, but I'm sure that all image
and bitmap-objects are disposed after processing (with this method,which
is, I think more than should be necessary to release the file lock)
private static void DisposeImage(Im age image)

{
image.Dispose() ;
image = null;
GC.Collect();
}

Did anyone observe similar behaviour? Does anyone have any ideas what
could be the reason for this annoying file locks (e.g. error in threading
or whatever..)
Or, how could a workaround look like (which means how can I unlock a file
which was created by the same thread)

thx,
Albert


Jul 21 '05 #3
I'm not a 100% for the implementation of file reading in GDI.

But I would try not to use a filename but instead use a filestream which
you could explicitly close.
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Albert Greinöcker wrote:
Thanks for your response...

The only two ways I'm opening the images is either

Image img = Image.FromFile( filePath);

Or with a copy constructor

Are in this case any additional closing steps necessary?

""Patrik Löwendahl [C# MVP]"" <pa************ *************** ***@home.se>
schrieb im Newsbeitrag news:OX******** ******@tk2msftn gp13.phx.gbl...
You should always make sure that you close the streams used to load the
images as well.

Maybe that is the problem you're experiencing?

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Albert Greinöcker wrote:
Hi ng,

I have a very strange problem within my c# application:
One of the (background) Threads in my application is responsible for some
image processing tasks (like resizing, clipping, ..) on a list of files.
Therefore, some temporary files are created which should be deleted after
processing is finished.
This Thread is called several times. When I call it the first time,
everything 's ok and no errors occur.
In the second call, I can observe very strange behaviour: I cannot delete
the temporary files created by this thread, but I'm sure that all image
and bitmap-objects are disposed after processing (with this method,which
is, I think more than should be necessary to release the file lock)
private static void DisposeImage(Im age image)

{
image.Dispose() ;
image = null;
GC.Collect();
}

Did anyone observe similar behaviour? Does anyone have any ideas what
could be the reason for this annoying file locks (e.g. error in threading
or whatever..)
Or, how could a workaround look like (which means how can I unlock a file
which was created by the same thread)

thx,
Albert


Jul 21 '05 #4
I'm also not very happy with the GDI-implementation. ..
which alternative would you advice?

""Patrik Löwendahl [C# MVP]"" <pa************ *************** ***@home.se>
schrieb im Newsbeitrag news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I'm not a 100% for the implementation of file reading in GDI.

But I would try not to use a filename but instead use a filestream which
you could explicitly close.
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Albert Greinöcker wrote:
Thanks for your response...

The only two ways I'm opening the images is either

Image img = Image.FromFile( filePath);

Or with a copy constructor

Are in this case any additional closing steps necessary?

""Patrik Löwendahl [C# MVP]"" <pa************ *************** ***@home.se>
schrieb im Newsbeitrag news:OX******** ******@tk2msftn gp13.phx.gbl...
You should always make sure that you close the streams used to load the
images as well.

Maybe that is the problem you're experiencing?

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Albert Greinöcker wrote:

Hi ng,

I have a very strange problem within my c# application:
One of the (background) Threads in my application is responsible for
some image processing tasks (like resizing, clipping, ..) on a list of
files.
Therefore , some temporary files are created which should be deleted
after processing is finished.
This Thread is called several times. When I call it the first time,
everything' s ok and no errors occur.
In the second call, I can observe very strange behaviour: I cannot
delete the temporary files created by this thread, but I'm sure that all
image and bitmap-objects are disposed after processing (with this
method,whic h is, I think more than should be necessary to release the
file lock)
private static void DisposeImage(Im age image)

{
image.Dispose() ;
image = null;
GC.Collect();
}

Did anyone observe similar behaviour? Does anyone have any ideas what
could be the reason for this annoying file locks (e.g. error in
threading or whatever..)
Or, how could a workaround look like (which means how can I unlock a
file which was created by the same thread)

thx,
Albert


Jul 21 '05 #5

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

Similar topics

6
7313
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
0
3932
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
5
1523
by: Fabio R. | last post by:
To support a webfarm scenario, I'd like to store a global array (serialized) in a file on a network share. In this array there is a list of pages "locked" by other users so I need to read this array at every page access to detect if the page is "free" so the user can access it; when the user can access the page, the page is added to the array so the next user can't access. What's the best way to lock this (network) file so when 2 users...
4
2762
by: hkappleorange | last post by:
I ued this code to connect to a mdb file A = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Inetpub\wwwroot\ASPX\Authors.mdb" )
0
2560
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming that the document properties cannot be read when a file is open, but it worked well in asp. ...
1
19920
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access it, it throws an exception. How to solave this problem? So second process can wait until first process completes its processing on the file. Thanks in advance
5
20273
by: cmay | last post by:
The only examples I have seen on how to check if a file is locked is to try to open it a catch an exception. MS has stated that you should never use error trapping in this manner. Is there no other way to identify if a file is locked w/o trapping an exception?
6
6016
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3dee5550b6d3652/ed00977acf62484f?lnk=gst&q=%27copying+locked+files%27&rnum=1 The problem is that I have a script that can find the pst files on every machine in my network and back them up to a server for safe keeping. The problem is that when Outlook is running it locks the...
0
961
by: Dmitry Teslenko | last post by:
Hello! I use some script in python 2.5 from vim editor (it has python bindings) that updates some file and then launches another program (ms visual studio, for example) to do something with updated file. I faced problem when updated file is locked for writing until vim editor is closed. launch vim -update file -launch msvc -file locked launch vim -update file -launch msvc -close vim -file locked
0
1504
by: Gabriel Genellina | last post by:
En Tue, 13 May 2008 11:57:03 -0300, Dmitry Teslenko <dteslenko@gmail.com> escribió: Is the code above contained in a function? So all references are released upon function exit? If not, you could try using: del input, output, filter That should release all remaining references to the output file, I presume. Or locate the inner reference to the output file (filter.something perhaps?) and explicitely close it.
0
8462
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
8802
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...
1
8586
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
8658
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
7405
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
6209
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
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.