473,545 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When I get the image from the file the file remains locked

When I get the image from the file the file remains locked so the Delete
fails with a "used by another process"

So I tried using a clone and disposing the obtained image.

But that didn't fix the problem.

Can you help?

Dim zz As Image = Image.FromFile( imageFileName)

MyImage = zz.Clone

zz.Dispose()

zz = Nothing

File.Delete(ima geFileName)
Jan 17 '06 #1
19 2223
hi,
the problem here with cloning method is it also copies the reference
of the file that is loaded in the IMAGE object so that if you dispose
the zz object after cloning, it passes reference of the file to MyImage
object that's why ultimately the file remains locked.

try this code. this should solve your problem

Dim fs As New StreamReader("C :\all.jpg")
Dim img As Image = Image.FromStrea m(fs.BaseStream )
fs.Close()
PictureBox1.Ima ge = img
File.Delete("C: \all.jpg")
Lucky

Jan 17 '06 #2

I'd really like to know if this works. The Kodak Image drivers in Windows
98 and NT4 have the same problem. I always thought this was a bug in the
Kodak drivers, but if it exists in .NET (which doesn't use the Kodak
drivers) as well, then the problem may actually be in the underlying Win32
API.

Mike Ober.

"Lucky" <tu************ @gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
hi,
the problem here with cloning method is it also copies the reference
of the file that is loaded in the IMAGE object so that if you dispose
the zz object after cloning, it passes reference of the file to MyImage
object that's why ultimately the file remains locked.

try this code. this should solve your problem

Dim fs As New StreamReader("C :\all.jpg")
Dim img As Image = Image.FromStrea m(fs.BaseStream )
fs.Close()
PictureBox1.Ima ge = img
File.Delete("C: \all.jpg")
Lucky


Jan 17 '06 #3
well first you need to understand the behaviour of the class and the
way it treats the resources.

in your case IMAGE class lock the resources so that if any call for
refresh/reload needs to attend by the object than the original data can
be reloaded or modified by the object itself.

i dont know why it is like this in IMAGE class but MS has implimented
it this way only.

run my code and compare it with your's and you'll see the difference
and behaviour of the class

Lucky

Jan 17 '06 #4
A bug, or a "feature"? I seem to recall a similar problem and found a
this reference that provided some insight.

http://support.microsoft.com/?id=814675

Cheers,
Randy

Michael D. Ober wrote:

I'd really like to know if this works. The Kodak Image drivers in Windows
98 and NT4 have the same problem. I always thought this was a bug in the
Kodak drivers, but if it exists in .NET (which doesn't use the Kodak
drivers) as well, then the problem may actually be in the underlying Win32
API.

Mike Ober.

"Lucky" <tu************ @gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
hi,
the problem here with cloning method is it also copies the reference
of the file that is loaded in the IMAGE object so that if you dispose
the zz object after cloning, it passes reference of the file to MyImage
object that's why ultimately the file remains locked.

try this code. this should solve your problem

Dim fs As New StreamReader("C :\all.jpg")
Dim img As Image = Image.FromStrea m(fs.BaseStream )
fs.Close()
PictureBox1.I mage = img
File.Delete(" C:\all.jpg")
Lucky


Jan 17 '06 #5
Thanks a lot

"Lucky" <tu************ @gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
hi,
the problem here with cloning method is it also copies the reference
of the file that is loaded in the IMAGE object so that if you dispose
the zz object after cloning, it passes reference of the file to MyImage
object that's why ultimately the file remains locked.

try this code. this should solve your problem

Dim fs As New StreamReader("C :\all.jpg")
Dim img As Image = Image.FromStrea m(fs.BaseStream )
fs.Close()
PictureBox1.Ima ge = img
File.Delete("C: \all.jpg")
Lucky

Jan 17 '06 #6
" **Developer**" <RE************ *@a-znet.com> schrieb:
When I get the image from the file the file remains locked so the Delete
fails with a "used by another process"


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 17 '06 #7
I don't think I can use your suggestion. I try to make it easy to see the
problem by shorting the code but I'm afriad I cut out too much code. Below
might be more then required to show the problem but I hope I didn't cut
anything relavent.

I believe the problen code starts where I left the blank lines below.

Dim wiaManager As WiaClass = Nothing ' WIA manager COM object

Dim wiaDevs As CollectionClass = Nothing ' WIA devices collection COM object

Dim wiaRoot As ItemClass = Nothing ' WIA root device COM object

Dim wiaPics As CollectionClass = Nothing ' WIA collection COM object

Dim wiaItem As ItemClass = Nothing ' WIA image COM object

Dim imageFileName As String

wiaManager = New WiaClass ' create COM instance of WIA manager

wiaDevs = wiaManager.Devi ces '

wiaDevs = wiaManager.Devi ces ' as CollectionClass ; ' call Wia.Devices to get
all devices

If wiaDevs Is Nothing OrElse wiaDevs.Count = 0 Then

MessageBox.Show ("No WIA devices found!", "WIA", MessageBoxButto ns.OK,
MessageBoxIcon. Stop)

Application.Exi t()

Return Nothing

End If

Dim selectUsingUI As Object = System.Reflecti on.Missing.Valu e ' = Nothing

wiaRoot = CType(wiaManage r.Create(select UsingUI), ItemClass) ' Display form
to let the user select device

If wiaRoot Is Nothing Then ' nothing to do

Return Nothing

End If

wiaPics = wiaRoot.GetItem sFromUI(WiaFlag .SingleImage,
WiaIntent.Image TypeColor) 'Open acquisition form to get a single image.

If wiaPics Is Nothing Then

Return Nothing

End If

Dim wiaObj As Object = wiaPics.Item(0)

wiaItem = CType(Marshal.C reateWrapperOfT ype(wiaObj, GetType(ItemCla ss)),
ItemClass)

imageFileName = Path.GetTempFil eName() ' create temporary file for image

wiaItem.Transfe r(imageFileName , False) ' Now do the scan and then transfer
picture to our temporary file (only way to get it)

Dim zz As Image = Image.FromFile( imageFileName) ' create Image instance from
file

AcquireScanner = zz.Clone

zz.Dispose() 'Unlock the file

zz = Nothing

File.Delete(ima geFileName)
When I get the image from the file the file remains locked so the Delete fails with a "used by another process" So I tried using a clone and disposing the obtained image. But that didn't fix the problem. Can you help?



Jan 17 '06 #8
Thanks, please see reply I just sent Lucky's first post
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:ue******** ******@TK2MSFTN GP11.phx.gbl...
" **Developer**" <RE************ *@a-znet.com> schrieb:
When I get the image from the file the file remains locked so the Delete
fails with a "used by another process"


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 17 '06 #9
What is the penalty for not deleting a temp file?

Is that a way to go?

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:ue******** ******@TK2MSFTN GP11.phx.gbl...
" **Developer**" <RE************ *@a-znet.com> schrieb:
When I get the image from the file the file remains locked so the Delete
fails with a "used by another process"


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 17 '06 #10

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

Similar topics

9
4905
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST == "") { include ("InsertRecord.inc"); // Insert new record }
0
2545
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...
2
3742
by: Mark | last post by:
Hello, Say I write a picture file to: 'c:\test.jpg' Then I assign this picture to a picturebox PbFoto.Image = Image.Fromfile("c:\test.jpg") Next I want the overrwrite the file test.jpg with another picture. When running, he says the file is in use when I want to overwrite it.
4
1841
by: chad.a.morris | last post by:
I'm new to Crystal Reports, so this may be a dumb problem, but I just can't figure it out. Basically, I want to control the selected data in the C# code as opposed to Crystal Reports (since SQL is truly for querying, and Crystal Reports is more a reporting tool). The only way I've found to do this so far is to execute my select in C#, then...
3
2815
by: thebhone | last post by:
I am creating a website updater program. Currently working on the image replacement module here. For some reason, after an image (say /images/1.jpg) has been used/opened in the application. I cannot later overwrite it (during the application), even after i have closed it.
6
7602
by: JezB | last post by:
I have an Image object (i) which I want to write to a file. This does work but when I later try to do something with this file I get errors, because I think the file is still 'locked'. I have to restart the application before the locks are released. I tried it first as: Image i = ... ; // correctly instantiated to some image...
8
2570
by: MarkAurit | last post by:
I have to display some images kept into a sql server database (image data type) in an asp.net 1.1 page. Is it possible to use an asp control to display the contents of a byte or a MemoryStream? Thanks much
2
2314
by: jim-on-linux | last post by:
py help, The file below will run as a stand alone file. It works fine as it is. But, when I call it from another module it locks my computer, The off switch is the only salvation. This module when run as a stand alone, it will
5
2267
by: buu | last post by:
I have an app made in vb.net with a part of it made in vc.net. after finishing a data processing with a file, I would like to delete that file, but file remains locked to be sure, I was: - closing file (in part made in vc.net) - closing object (vc) - calling GC.Collect - calling GC.WaitForPendingFinalizers
0
7490
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...
0
7682
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. ...
0
7935
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...
1
7449
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...
0
7780
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...
1
5351
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...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
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...

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.