Hi All, I am running into a concurrency problem. I have a worker process
which reads some data out of a file and inserts fresh data into it. I have
put a Monitor.Enter(this) and Monitor.Exit(this) on both of the routines
which do read and writes.
The worker process is spawned off by a Multithreaded application. I am
seeing error in log which tells me that
Description:
Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode)
at System.Data.DataSet.WriteXml(String fileName)
Message-The process cannot access the file "C:\WUTemp\foocache.xml" because
it is being used by another process.
Inner Exception-
Source-mscorlib
Base Exception Message-The process cannot access the file
"C:\WUTemp\foocache.xml" because it is being used by another process.
Base Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String
str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode)
at System.Data.DataSet.WriteXml(String fileName)
Base Source-mscorlib
Earlier I tried using the Reader and Writer locks too...but ran into timeout
errors...
How do Rectify this?
TIA 5 1449
Hi, Vai2000
It looks like you don not close file when using it - basically that means
you are trying to access same file from at least 2 different threads and
second thread cannot get access. Check where you open file before entering
monitor and if you close it properly before exiting.
HTH
Alex
"Vai2000" <no****@microsoft.com> wrote in message
news:Oc****************@tk2msftngp13.phx.gbl... Hi All, I am running into a concurrency problem. I have a worker process which reads some data out of a file and inserts fresh data into it. I have put a Monitor.Enter(this) and Monitor.Exit(this) on both of the routines which do read and writes. The worker process is spawned off by a Multithreaded application. I am seeing error in log which tells me that Description: Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String
str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String
msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding) at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) at System.Data.DataSet.WriteXml(String fileName) Message-The process cannot access the file "C:\WUTemp\foocache.xml"
because it is being used by another process. Inner Exception- Source-mscorlib Base Exception Message-The process cannot access the file "C:\WUTemp\foocache.xml" because it is being used by another process. Base Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode,
String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String
msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding) at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) at System.Data.DataSet.WriteXml(String fileName) Base Source-mscorlib
Earlier I tried using the Reader and Writer locks too...but ran into
timeout errors...
How do Rectify this?
TIA
Vai2000 <no****@microsoft.com> wrote: Hi All, I am running into a concurrency problem. I have a worker process which reads some data out of a file and inserts fresh data into it. I have put a Monitor.Enter(this) and Monitor.Exit(this) on both of the routines which do read and writes.
It's a bad idea to lock on "this" - see http://www.pobox.com/~skeet/csharp/m...ml#lock.choice
The worker process is spawned off by a Multithreaded application. I am seeing error in log which tells me that Description: Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding) at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) at System.Data.DataSet.WriteXml(String fileName) Message-The process cannot access the file "C:\WUTemp\foocache.xml" because it is being used by another process.
Right. That suggests that you haven't closed the file earlier - or that
a different process is indeed using it, or that another thread is
trying to use it at the same time.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Here's little more scoop to the Problem.
--- ProcessA calls x number of WorkerThreads which try to access a file for
reading and writing.
-- Main Process can potentially Launch x number of ProcessA
How do I guard the resource...hack way is to put the stuff in DB and read
and write off the DB but I don't want any R/T over the wire!!!
Temp solution was that I have applied delay on the Main process which calls
ProcessA and at this time ProcessA is launching only 1 Thread.
But need some solid solution.
Appreciate all ur inputs
TIA
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Vai2000 <no****@microsoft.com> wrote: Hi All, I am running into a concurrency problem. I have a worker process which reads some data out of a file and inserts fresh data into it. I
have put a Monitor.Enter(this) and Monitor.Exit(this) on both of the routines which do read and writes.
It's a bad idea to lock on "this" - see http://www.pobox.com/~skeet/csharp/m...ml#lock.choice
The worker process is spawned off by a Multithreaded application. I am seeing error in log which tells me that Description: Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String
str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String
msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding) at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) at System.Data.DataSet.WriteXml(String fileName) Message-The process cannot access the file "C:\WUTemp\foocache.xml"
because it is being used by another process.
Right. That suggests that you haven't closed the file earlier - or that a different process is indeed using it, or that another thread is trying to use it at the same time.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Guard the resource with a mutex, or better use a queue to post the IO
requests from your worker threads to a single thread to do your 'shared'
file IO.
Willy.
"Vai2000" <no****@microsoft.com> wrote in message
news:uY**************@TK2MSFTNGP09.phx.gbl... Here's little more scoop to the Problem. --- ProcessA calls x number of WorkerThreads which try to access a file for reading and writing. -- Main Process can potentially Launch x number of ProcessA
How do I guard the resource...hack way is to put the stuff in DB and read and write off the DB but I don't want any R/T over the wire!!!
Temp solution was that I have applied delay on the Main process which calls ProcessA and at this time ProcessA is launching only 1 Thread.
But need some solid solution.
Appreciate all ur inputs
TIA
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Vai2000 <no****@microsoft.com> wrote: > Hi All, I am running into a concurrency problem. I have a worker > process > which reads some data out of a file and inserts fresh data into it. I have > put a Monitor.Enter(this) and Monitor.Exit(this) on both of the > routines > which do read and writes.
It's a bad idea to lock on "this" - see http://www.pobox.com/~skeet/csharp/m...ml#lock.choice
> The worker process is spawned off by a Multithreaded application. I am > seeing error in log which tells me that > Description: > Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode, String str) > at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess > access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, > Boolean bFromProxy) > at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess > access, FileShare share) > at System.Xml.XmlTextWriter..ctor(String filename, Encoding > encoding) > at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) > at System.Data.DataSet.WriteXml(String fileName) > Message-The process cannot access the file "C:\WUTemp\foocache.xml" because > it is being used by another process.
Right. That suggests that you haven't closed the file earlier - or that a different process is indeed using it, or that another thread is trying to use it at the same time.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
thanks, do you mean MSMQ ? can you bring some more insight on this.
TIA
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl... Guard the resource with a mutex, or better use a queue to post the IO requests from your worker threads to a single thread to do your 'shared' file IO.
Willy.
"Vai2000" <no****@microsoft.com> wrote in message news:uY**************@TK2MSFTNGP09.phx.gbl... Here's little more scoop to the Problem. --- ProcessA calls x number of WorkerThreads which try to access a file for reading and writing. -- Main Process can potentially Launch x number of ProcessA
How do I guard the resource...hack way is to put the stuff in DB and
read and write off the DB but I don't want any R/T over the wire!!!
Temp solution was that I have applied delay on the Main process which calls ProcessA and at this time ProcessA is launching only 1 Thread.
But need some solid solution.
Appreciate all ur inputs
TIA
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Vai2000 <no****@microsoft.com> wrote: > Hi All, I am running into a concurrency problem. I have a worker > process > which reads some data out of a file and inserts fresh data into it. I have > put a Monitor.Enter(this) and Monitor.Exit(this) on both of the > routines > which do read and writes.
It's a bad idea to lock on "this" - see http://www.pobox.com/~skeet/csharp/m...ml#lock.choice
> The worker process is spawned off by a Multithreaded application. I
am > seeing error in log which tells me that > Description: > Stack Trace- at System.IO.__Error.WinIOError(Int32 errorCode,
String str) > at System.IO.FileStream..ctor(String path, FileMode mode,
FileAccess > access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, > Boolean bFromProxy) > at System.IO.FileStream..ctor(String path, FileMode mode,
FileAccess > access, FileShare share) > at System.Xml.XmlTextWriter..ctor(String filename, Encoding > encoding) > at System.Data.DataSet.WriteXml(String fileName, XmlWriteMode
mode) > at System.Data.DataSet.WriteXml(String fileName) > Message-The process cannot access the file "C:\WUTemp\foocache.xml" because > it is being used by another process.
Right. That suggests that you haven't closed the file earlier - or that a different process is indeed using it, or that another thread is trying to use it at the same time.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rnn98 |
last post by:
hi,
my multithread application, running under solaris box, is crashing
eventually.
I tried to spot and substitute functions not "thread safe", but I
guess my search wasn't good enough. I have put...
|
by: Bill Davidson |
last post by:
Hello All:
I've got a question about synchronization requiremements in a C# worker
thread procedure that, among other things, sinks events from outside
sources. I realize the worker thread will...
|
by: Bill Davidson |
last post by:
(RESEND: I added a little more code to the sample for clarity)
Hello All:
I've got a question about synchronization requiremements in a C# worker
thread procedure that, among other things,...
|
by: James Lavery |
last post by:
Hi everyone,
We're developing an application to capture data from several serial
ports, store in a database, and (optionally) forward on using FTP.
Each serial port is being processed in a...
|
by: Morpheus |
last post by:
Hi,
I have been coding in Windows for many years so have a mindset to it,
so forgive any stupid questions.
Is it possible to create a multithread application in C++ that is
portable...
|
by: Sergey Poberezovskiy |
last post by:
I have the following code in C# that I have trouble converting to VB(2.0):
private delegate void openDialog();
private void openWindowsDialog(openDialog open)
{
Thread thread = new Thread(new...
|
by: Creativ |
last post by:
Why does Thread class not support IDisposable? It's creating quite
some problem. Namely, it can exhaust the resource and you have not
control over it.
|
by: Hapa |
last post by:
Does only reading (never writing) of a variable need thread synchronisation?
Thanks for help?
PS.
Anybody knows a Visual C++ news group?
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a routine that builds a table using different queries, different SQL
Tables, and adding custom fields.
It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the
table...
|
by: k3xji |
last post by:
Hi all,
This will probably be a long question/short answer, sorry, but I have
wandered net about the subject and really feel cannot find just enough
information.I want to ask my question by...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |