Logging problem using the Reader.Read() and lots of processing inside

Naomi Nosonovsky 7,881 Reputation points
2020-12-18T17:47:49.617+00:00

Hi everybody,

I've been working on changes in the application written by someone else. The way the program is structured is that the query is executed into a reader (it may return up to 300 rows). It then reads data and saves them into public fields of a class, updates info with these same values in another class as well, tries to process the file name it reads and tries to move it into a different folder and also updates two tables where one of them is huge (every day about 500K+ rows written into that table - it is used for auditing all the actions).

Now, I found the following in that audit table:

LFD id: 88777 File processing error. 88777
Processing LFD Id: 88773 88773
Processing LFD Id: 88777 88777

The error message and the ID is actually wrong. It's the 88773 which produced the error, not 88777 as reported in the Audit (this is probably next file in sequence).

Do you know why do I have this problem and how to fix it so the correct file is reported? I can share some relevant code if needed (all the code is currently in the main program but it uses another class to write into audit table or in the main table).

The other strange thing is that only one error message is recorded in the other table even though the code is not supposed to reset last error message or last error time. It could be that this information is overwritten by some other process, though - I may need to do more research on that.

For now do you have an explanation as why do I get the incorrect ID recorded in the Audit table and do I have to keep some variable instead of assigning classes fields directly and using them for logging information in the reader.read() loop?

Thanks in advance.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,006 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 118K Reputation points
    2020-12-19T06:34:19.537+00:00

    If the code includes some asynchronous parts, maybe you should create new objects instead of altering the object fields directly, which are still in use by asynchronous parts.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.