473,698 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File used by another process C#

1 New Member
I use filesystemwatch er in the created event i go read the file sequentially do some checks and then close the straem reader then i move the file chang the name and the directory.
Expand|Select|Wrap|Line Numbers
  1. private void WABfileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
  2.         {
  3.     foreach (FileInfo INF in WABdir.GetFiles("*.spl"))
  4.             {
  5. // do something with the stream reader and writer
  6.  streamreader1.Close(); //closing file reader
  7. sw.close(); // closing file writer
  8. File.Move(INF.FullName,@"D:\LIDOArchive\WAB\Accepted Messages\" + INF.Name.Replace(".spl", "") + "_" + DateTime.Now.ToShortDateString().Replace(@"/", "") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".spl");
  9. }
  10. }
  11.  
why it keeps getting this error, is there is something i should write to make the program wait like 300 milsec to let windows release the file or what.
also i get more than 800 files at once and i use the thread.sleep(10 00) but still get that error the funny thing that there is no files stocked in the folder they all moved but error exists how is that any ideas??
Aug 26 '10 #1
1 1838
Plater
7,872 Recognized Expert Expert
Are you protecting against re-entry in your event handler?
The process that has the file in use might be your own!
Aug 31 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
8326
by: Mountain Bikn' Guy | last post by:
I am having serious problems with the following IDE bug: Could not write to output file 'x.dll' -- 'The process cannot access the file because it is being used by another process. ' and BUG: "Could Not Copy Temporary Files to the Output Directory" Error Message When You Build a Solution That Contains Multiple Projects I have tried all the solutions in Microsoft Knowledge Base Article - 313512.
8
26712
by: Gabe Moothart | last post by:
Hi, I'm writing a windows service which interacts with a separate process. Basically, it calls a process which creates a file, and then my service reads that file. The problem is, the external process can take a second or two to finish writing the file. If I try to read the file to soon, I get an exception that "The process cannot access the file because it is being used by another process". I could just set a timer, but the time it...
4
27135
by: funkmusha | last post by:
I am trying to read a log file using vb.net. I get an error stating "The process cannot access the file 'C:\test.log' because it is being used by another process." Below is a sample of what I am trying to do. The var logFileName is being passed into the function. Dim line as String Dim sr As New StreamReader(logFileName) 'It dies on this line Do line = sr.ReadLine()
13
11141
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on the "log files". There are no file sharing problem.
0
2957
nightangel
by: nightangel | last post by:
Hi dude,what i was done in my application is uploading a image file to my server using FTP, it work great when pushing a file into the server path using FTP. The problem i met now is i need to do a resuming for the file uploading if the client connection or server connection is down. E.g: Sunset.jpg (500KB) when i upload until half of it, (332KB in the server) and unplug my connection, it will looping and try to connect to the server, after...
6
16997
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a vxworks OS. I'm reading the file using MFC on a windows XP PC. The file is stored on a Windows 2000 server. I tried using CStdioFile.Open using the CFile::modeRead flag. When did this i received a CFileException with the cause stating...
2
1577
by: Newbie | last post by:
Hi, I have a situation where my application is trying to access a file, that another application may have temporalily open. The error I get is The process cannot access the file 'C:\picks\test50k.gp1' because it is being used by another process.
0
1848
by: Tim Golden | last post by:
aditya shukla wrote: Why on earth are you *specifying* c:\python25 as the directory for this file? It's automatically created in your user-specific temp directory which has specific permissions and is (obviously) specific to that user. You may -- depending on your needs -- also not need the suffix & prefix. ie, unless you have some specific need in mind, just use:
3
2221
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I am trying to loop a Textfile. This Textfile is located on a shared drive and it is used by another process. When I try to read it I get an exeption: The process cannot access the file 'file.log' because it is being used by another process.
3
3334
by: gracepaul | last post by:
hi, i got an exception while i m trying to zip/unzip a database inside the serverfolder System.IO.IOException: The process cannot access the file 'E:\hshome\holsoftsystems\indusmotor.co.in\MTNMRN1\MTNMRN1\MTNMRN2\Hrm123.ldb' because it is being used by another process. the database is being used by another process. i have to zip this database and download it provided it can be used by another process. how can i do this i use the...
1
8895
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
8861
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
7728
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
6518
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
5860
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();...
0
4369
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2330
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.