472,779 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

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(Image 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 13577
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(Image 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**************@tk2msftngp13.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(Image 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**************@tk2msftngp13.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(Image 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****************@TK2MSFTNGP12.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**************@tk2msftngp13.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(Image 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
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
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....
5
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...
4
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
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...
1
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...
5
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...
6
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. ...
0
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...
0
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.