It's not very clear what you mean by "threads inserting rows to the wrong tables".
Your code is surely faulty unless you pass to the thread all the information it needs
to do its work; it cannot make any blind assumptions based on processing order or
anything else that can vary. For example, passing a stream to read from without
passing to it the name of the table to which the result should be written makes no
sense.
Any information you need can be placed in a class that's passed to the thread.
It seems to me that you should pass the name of the file to read and the table to
which it should write the data it reads; possibly, you should also be passing the size
of the file as it was the last time it was read. (The last item would make sure that
if more than one line has been added since the last time the service read the file,
all will be added to the database. That value should be returned to the main service,
so it can be used the next time.)
Good luck.
At 05:37 AM 10/14/2004, arie ansel wrote
>I coded window services that watch folders for line addition to file in
>those folders.
>On file watch event it parse the file and insert the last line to a mssql
>server
>Since I have about 50 sources (tests values returned from various
>instruments) updating the files I opened thread for each file io.
>I can't count on the parsing returned in the same order it entered because
>the files are big and different size.
>My question is how to block threads inserting rows to the wrong tables?
>
>I locked the relevant values
>
>---------------------
>state _state;
>IDictionary settings ;
>lock(finishedLock)
>{
>// sql table columns names
>settings =
>(IDictionary)System.Configuration.ConfigurationSettings.GetConfig("ImpFiles"
>) ;
>// file stream returned from BeginRead
>
>_state = (state) asyncResult.AsyncState;
> }
>--------------------
>
>Am I doing it right? Is it redundant anyway ?
>
>
>TIA
>
>A
J. Merrill / Analytical Software Corp
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
Essential .NET: building applications and components with CSharp
August 30 - September 3, in Los Angeles
http://www.develop.com/courses/edotnet
View archives and manage your subscription(s) at http://discuss.develop.com