By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,257 Members | 1,167 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,257 IT Pros & Developers. It's quick & easy.

C# Write lines to file at high volume, multiple threads

P: n/a
Hi -

I am attempting to write lines to a file at high volume, multiple threads.
Here is my scenario:

(initial "WriteToFile" object created via a parent multithreaded process,
which receives files, can call custom code for each file received - much like
BizTalk)

1. Receive multiple files, each file received creates a "WriteToFile" object
2. Each "WriteToFile" object parses it's file, creates a line, and attempts
to write that line to a specified file. Most or all of the "WriteToFile"
objects will be attempting to write to the same file.
3. If a "WriteToFile" object can't write it's data to the file, it should
throw an exception, handle it, and try again.

Questions:
1. Would this be better handled as a Windows service which reads files from
a queue and processes them serially?

2. If I didn't want to use a queue or service approach, what could I use to
check whether a file is accessible or not? Ie: Is some other process writing
to it?

3. Any code suggestions for a high volume file-write service or process?

Thaks for your help in advance!
--
Dameon
May 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Dameon" <Da****@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.com...
Hi -

I am attempting to write lines to a file at high volume, multiple threads.
Here is my scenario:

(initial "WriteToFile" object created via a parent multithreaded process,
which receives files, can call custom code for each file received - much
like
BizTalk)

1. Receive multiple files, each file received creates a "WriteToFile"
object
2. Each "WriteToFile" object parses it's file, creates a line, and
attempts
to write that line to a specified file. Most or all of the "WriteToFile"
objects will be attempting to write to the same file.
3. If a "WriteToFile" object can't write it's data to the file, it should
throw an exception, handle it, and try again.

Questions:
1. Would this be better handled as a Windows service which reads files
from
a queue and processes them serially?

2. If I didn't want to use a queue or service approach, what could I use
to
check whether a file is accessible or not? Ie: Is some other process
writing
to it?

3. Any code suggestions for a high volume file-write service or process?
I think if you want a high volume file writing, you want a single thread
writing to the file and the WriteToFile objects should parse it's file,
create a line and pass that line to the file writer thread by adding it to a
Queue of lines to be written.

May 11 '07 #2

P: n/a
I'd use file proxy object servicing the queue of requests

It can sit on separate thread and be waken up by monitor event by any other
posting thread. File access code then is encapsulated in proxy object. For
high volume you need to use asynch mode or file writing

If you have multiple files, you can create multiple proxies. Sending threads
can use global queue, which might distribute payload to corresponding proxy
queue. Could be done as service or as module in your application (or
plug-in).

As about locking, if only you write to the file, you can open it in
exclusive mode.

HTH
Alex

"Dameon" <Da****@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.com...
Hi -

I am attempting to write lines to a file at high volume, multiple threads.
Here is my scenario:

(initial "WriteToFile" object created via a parent multithreaded process,
which receives files, can call custom code for each file received - much
like
BizTalk)

1. Receive multiple files, each file received creates a "WriteToFile"
object
2. Each "WriteToFile" object parses it's file, creates a line, and
attempts
to write that line to a specified file. Most or all of the "WriteToFile"
objects will be attempting to write to the same file.
3. If a "WriteToFile" object can't write it's data to the file, it should
throw an exception, handle it, and try again.

Questions:
1. Would this be better handled as a Windows service which reads files
from
a queue and processes them serially?

2. If I didn't want to use a queue or service approach, what could I use
to
check whether a file is accessible or not? Ie: Is some other process
writing
to it?

3. Any code suggestions for a high volume file-write service or process?

Thaks for your help in advance!
--
Dameon

May 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.