472,114 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

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

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
2 11180
"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
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.

Similar topics

7 posts views Thread by Irmen de Jong | last post: by
5 posts views Thread by nicolas_riesch | last post: by
18 posts views Thread by jas | last post: by
3 posts views Thread by lltaylor | last post: by
2 posts views Thread by Arsen V. | last post: by
5 posts views Thread by Sumana | last post: by
reply views Thread by leo001 | last post: by

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.