Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there is about 200 .txt file in a server , every file have about 20 number. these files change every 10 second. capacity of each file is about 250 byte.

i want to use theme for draw a chart or calculating or ...every 10 second

what is best and fastest solution for this scenario ?

should i read theme online and save every number of files in a array ?
i want to use 10 thread and each thread read 20 files and save content of a file in one line of array . is it true ?
if i do this, can i read this array in same time with another thread ?

What I have tried:

i want to use 10 thread and each thread read 20 files and save content of a file in one line of array
Posted
Updated 23-Mar-16 21:49pm
Comments
RickZeeland 24-Mar-16 7:54am    
I agree with Beefcake, you need the FileSystemWatcher class, here is an example:
http://www.codeproject.com/Articles/58740/FileSystemWatcher-Pure-Chaos-Part-of

1 solution

As a general rule of thumb when considering a multi-threaded approach, consider if there is any latency in the thread that would benefit from parallelization.

In this case I suspect that you are thinking the wait time while waiting for a file to change is your latency.

A better performing model is to do the following.

1. Use a directory / file watching mechanism which reports changed/new files when they occur, do nothing in the event OTHER than set the dirty flag on the file item in your array.
2. Have a single thread that checks for dirty items, and then reads them from their file.
3. Have a render thread which a) copies your array to a second render array b) renders the chart from the render array

At all points you want to minimize the amount of time thread contention can occur, and use event driven mechanics where possible.
 
Share this answer
 
v2
Comments
itman2 25-Mar-16 2:28am    
thanks Beefcake
excuse me if my English isnt very well

about this scenario i should say : these file may chang every second or every 30 second or ... we dont know . but i must read them all every 10 second (for example) and use those content.
you said : 1. Use a directory / file watching mechanism which reports changed/new files ....
but i have no access to server just i can read 200 link like this :
http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=64358061873294912&c=64
i think this(no1 in your solution) mechanism isnt necessary ! (isnt it?)
Matt Comb 25-Mar-16 4:26am    
Ah yes, that does make a difference, because remote data introduces the latency I was mentioning.

In that case, what you have said is correct except that you should not render from the same array that you are populating from multiple threads. You should routinely copy (e.g. 10 sec) the first array to a second array and render from the second array, this will reduce the period where contention can occur

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900