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

File lock problem

Occasionally when I try and save a document:

-----------------------
xmlDoc.Save(Application.StartupPath + @"\Config.xml");
-----------------------

I get this error saying that the file could not be accessed because its
locked by another process or something (I cant get it to do it now - because
I want it to crash...)
Is there a way to check whether a file is locked by another process befre
trying to save it? If it is locked is there a way to terminate the other
process or somewhow free it up so that it can be saved?

Thanks,
Grant
Nov 17 '05 #1
10 14522
I can't answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.
Nov 17 '05 #2
I can't answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.
Nov 17 '05 #3
Hi,

No, AFAIK there is no way to know if a file is locked beforehand, you have
to open it and it will give you error, use a try/catch block .

It's possible to know what process is using a given file, filemon from
sysinternals.com does it. how ? frankly I have no idea , IIRC there is no a
easy way to get this info. of course there is not a managed way of doing it.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Grant" <gp*****@hotmail.com> wrote in message
news:uF**************@TK2MSFTNGP14.phx.gbl...
Occasionally when I try and save a document:

-----------------------
xmlDoc.Save(Application.StartupPath + @"\Config.xml");
-----------------------

I get this error saying that the file could not be accessed because its
locked by another process or something (I cant get it to do it now -
because I want it to crash...)
Is there a way to check whether a file is locked by another process befre
trying to save it? If it is locked is there a way to terminate the other
process or somewhow free it up so that it can be saved?

Thanks,
Grant

Nov 17 '05 #4
Hi,

No, AFAIK there is no way to know if a file is locked beforehand, you have
to open it and it will give you error, use a try/catch block .

It's possible to know what process is using a given file, filemon from
sysinternals.com does it. how ? frankly I have no idea , IIRC there is no a
easy way to get this info. of course there is not a managed way of doing it.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Grant" <gp*****@hotmail.com> wrote in message
news:uF**************@TK2MSFTNGP14.phx.gbl...
Occasionally when I try and save a document:

-----------------------
xmlDoc.Save(Application.StartupPath + @"\Config.xml");
-----------------------

I get this error saying that the file could not be accessed because its
locked by another process or something (I cant get it to do it now -
because I want it to crash...)
Is there a way to check whether a file is locked by another process befre
trying to save it? If it is locked is there a way to terminate the other
process or somewhow free it up so that it can be saved?

Thanks,
Grant

Nov 17 '05 #5
I can open the file ok and make modifications - its when I do the save bit
that it fails - is this where I would expect it to fail or when Im opening
the file?

Either way though Ill try open the file in a try catch block on a seperate
thread (now to learn how to do this on a seperate thread...)

Thanks for your help.

Grant

"CheshireCat" <ha*@notonyournelly.coom> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.

Nov 17 '05 #6
I can open the file ok and make modifications - its when I do the save bit
that it fails - is this where I would expect it to fail or when Im opening
the file?

Either way though Ill try open the file in a try catch block on a seperate
thread (now to learn how to do this on a seperate thread...)

Thanks for your help.

Grant

"CheshireCat" <ha*@notonyournelly.coom> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.

Nov 17 '05 #7

"Grant" <gp*****@hotmail.com> wrote in message
news:OQ*************@TK2MSFTNGP15.phx.gbl...
I can open the file ok and make modifications - its when I do the save bit
that it fails - is this where I would expect it to fail or when Im opening
the file?

Either way though Ill try open the file in a try catch block on a seperate
thread (now to learn how to do this on a seperate thread...)

Thanks for your help.

Grant


That means you still have your file open on the other thread, right?
If that's true, are you sure the file is opened for shared RW access?

Willy.
Nov 17 '05 #8

"Grant" <gp*****@hotmail.com> wrote in message
news:OQ*************@TK2MSFTNGP15.phx.gbl...
I can open the file ok and make modifications - its when I do the save bit
that it fails - is this where I would expect it to fail or when Im opening
the file?

Either way though Ill try open the file in a try catch block on a seperate
thread (now to learn how to do this on a seperate thread...)

Thanks for your help.

Grant


That means you still have your file open on the other thread, right?
If that's true, are you sure the file is opened for shared RW access?

Willy.
Nov 17 '05 #9
Grant,

What you ask has never been possible with any (regular) Microsoft OS.

It would be very nice when we could.

They have build themselves a special feature for that in Office.

Cor
Nov 17 '05 #10
how do you get a return value from a seperate thread? Ive got this far but I
dont know how to check whether the update was a success or not..

Thread updaterThread = new Thread(new ThreadStart(updateSomething));
updaterThread.Start();

Thanks,
Grant

"CheshireCat" <ha*@notonyournelly.coom> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I can't answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.

Nov 17 '05 #11

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

Similar topics

11
by: stu | last post by:
I have several databases that are opened using various versions of Access and VB. Up till recently everything worked fine, then I started getting a variety of lock file error messages, both on my...
4
by: KDB | last post by:
Hi, I am trying the following code to get a write lock on a file. #include <unistd.h> #include <iostream.h> #include <fcntl.h> main() { int fd = open("file",O_RDWR);
0
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
6
by: martin | last post by:
Hi, I have noticed that every aspx page that I created (and ascx file) has an assosiated resource file aspx.resx. However what I would like to do is have a single global resource file for the...
14
by: Gary Nelson | last post by:
Anyone have any idea why this code does not work? FileOpen(1, "c:\JUNK\MYTEST.TXT", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared) Dim X As Integer For X = 1 To 26 FilePut(1, Chr(X +...
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...
3
by: dchadha | last post by:
Hi, I am working on application in C# which uses and stores data in xml file. This app can use xml file from two different ways: (a) From User Interface (Windows application) and (b) From...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
5
by: pgdown | last post by:
Hi, I have several processes accessing files from one folder, but only one process should ever access each file. Once one process has the file, no other process should be allowed to access it,...
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...
0
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...

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.