Is there any way to forcibly release a lock on a text file, so that it can
be deleted?
I am testing an order-processing site that saves transaction information in
a text file that it attaches to its merchant notification. In most cases, it
works fine, but occasionally a lock on the text file won't get released.
When the next transaction comes along and tries to write over the file, the
server throws an IO error, saying that the file is in use by another
application.
What I'd like to do is forcibly release the lock, so that the file can be
deleted. Is that the right way to go about it? If so, how do I do it? If
not, what would be the best approach? Thanks.
David Veeneman
Foresight Systems 4 1447
You best bet is to write a good finally statement
Streamwriter sw = null;
try
{
//write to the file
Streamwriter sw = yada yada yada;
}
finally
{
if(null!=sw)
{
sw.Close();
}
}
Something like that.
the finally block runs whether an error happens or not.
If you're already doing that, then maybe give a little more detail.
"David Veeneman" <da****@nospam. comwrote in message
news:uP******** ******@TK2MSFTN GP02.phx.gbl...
Is there any way to forcibly release a lock on a text file, so that it can
be deleted?
I am testing an order-processing site that saves transaction information
in
a text file that it attaches to its merchant notification. In most cases,
it
works fine, but occasionally a lock on the text file won't get released.
When the next transaction comes along and tries to write over the file,
the
server throws an IO error, saying that the file is in use by another
application.
What I'd like to do is forcibly release the lock, so that the file can be
deleted. Is that the right way to go about it? If so, how do I do it? If
not, what would be the best approach? Thanks.
David Veeneman
Foresight Systems
You best bet is to write a good finally statement
Yeah, I've got that. But for some reason I've been unable to pin down, The
lock is still not getting released.
In those cases, i like to use wholockme utility or filemon from sysinternals
to see what actually holds the lock on the process. It may not be the
process you think it is. At least, it certainly doesn't help to confirm it.
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Veeneman" <da****@nospam. comwrote in message
news:eJ******** ********@TK2MSF TNGP04.phx.gbl. ..
>You best bet is to write a good finally statement
Yeah, I've got that. But for some reason I've been unable to pin down, The
lock is still not getting released.
On Feb 11, 10:37 pm, "Alvin Bruney [MVP]" <some guy without an email
addresswrote:
In those cases, i like to use wholockme utility or filemon from sysinternals
to see what actually holds thelockon the process. It may not be the
process you think it is. At least, it certainly doesn't help to confirm it.
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon andwww.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Veeneman" <dav...@nospam. comwrote in message
news:eJ******** ********@TK2MSF TNGP04.phx.gbl. ..
You best bet is to write a good finally statement
Yeah, I've got that. But for some reason I've been unable to pin down, The
lockis still not getting released.- Hide quoted text -
- Show quoted text -
Please send me your more inquiry or requirements to my e-mail address
to ke****@leadingw ay.com.tw
Best regards,
Kelvin Chang This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: McGeeky |
last post by:
Are there any best practices on releasing updates of an ASP.Net application
to a virtual directory in a production environment? E.g. is it okay to
simply copy over changes to ASP.Net pages in to the virtual directory whilst
IIS is still running or should IIS be stopped first?
--
McGeeky
http://mcgeeky.blogspot.com
|
by: Oenone |
last post by:
I've an ASP.NET 2.0 project into which various Plug-In DLLs can be
installed. I'm running it in the ASP.NET Development Server. In order to
load one of the PlugIn DLLs I'm using
System.Reflection.Assembly.LoadFrom(filename) to load the DLL and then
calling CreateInstance on the assembly that is returned.
This is all fine, but when I stop the project from running, change the code
and then re-compile it, I'm frequently getting a message...
|
by: Bram Stolk |
last post by:
Hello,
I've implemented, in C, a function that does a lot of I/O, and thus
can block for a long time.
If I execute this function in my Python script, it does not
relinquish the global interpreter lock, like Python's native
blocking functions do, like I/O funcs, and time.sleep() func.
|
by: John Wright |
last post by:
During my program I load an exe file using reflection. My program loads the
file using reflection, checks the assembly version and does an update if the
network version is different from the local version. I have a problem,
however, when I do the first check using reflection to get the network
version, then it locks the file and I can't delete it. How long will the
program maintain a lock on the file using reflection? I am setting the...
|
by: jeff.ranney |
last post by:
Hi all.
I wrote this C# code:
lock(this)
{
/ /write to a file
}
| |
by: Gina_Marano |
last post by:
Hey All,
I am using multiple child threads per main thread to download files.
It sometimes appears as if the same file is being downloaded twice. I
am using "lock". Am I using it correctly? Any blantant threading
errors here?
Any opinions would be greatly appreciated.
namespace MainThreadManagement
|
by: Peted |
last post by:
Hi
wondering what is the best way to do this
Need a user to click a button, that sends 3 or 4 string based commands
via a TCP/ip socket link
I can connect to the ip device no problems, am using indy sockets, and
can send information ok
|
by: Jennifer.Berube |
last post by:
What is it exactly that makes application.lock such a bad thing? I
just need a better explanation or link to a resource desribing it's
downfall.
|
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 write text into a text file.
// sample code
FileLogger logger = LogFactory.Get_Logger();
logger.Log("Message here");
|
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...
|
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...
| |
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |