-2

I have a class in a Windows Forms application that is processing at peak 10 - 20 records per minute, but at non-peak it might go two or three hours without doing anything.

As I see it, you can structure the FileHelpers engine lifecycle two ways:

  1. Create a new engine within the function where you need it.
  2. Create an engine in the class constructor and use that engine in all the member functions.

Now, if a member function runs as a separate task it makes sense to me that it might not be task safe to share the engine, but let's ignore that and assume it's all running in the UI thread.

So which is better?

Walt
  • 312
  • 3
  • 7

1 Answers1

0

I am not sure that this is really a question which fits normal StackOverflow requirements, as this is not really a code problem but a question of preference or needs, and therefore can be subjective. The reasons I would say this is because you have to take into account many things including what your processing and whether your planning for it to be scalable.

For scability, you have to take into account how much memory is utilised, what the initialisation time is, and whether the engine would operate safely across your classes if you are attempting to use a singleton.

The other issues you'd have to cover is whether you are using the generic engine with runtime typing, or you are using the type-based engine.

Personally, for safety, I would initiate a new engine for each processing request if you are using tasks or multi-threading as long as the initialisation time is short. Otherwise, if the initialisation time is long, create a singleton with a queue but then you need to balance how big that queue can get.

Effectively, you are trying to balance it so that you are picking Init+((Process)x#) or Init+((Queue+Process)x#) is the shorter and safer to implement.

Not sure if that truly answers your question but hopefully it's a start.

netniV
  • 2,328
  • 1
  • 15
  • 24
  • 1
    Your first sentence is a reason you should vote the question to be closed, not answered. Do not answer off topic questions. [answer] – Rob Jan 15 '22 at 10:27
  • Like I said, I wasn’t sure. So not definitive. If you feel it should be closed, you can certainly flag it to be so. – netniV Jan 15 '22 at 14:13
  • SO is referenced in FH's limited documentation as the place to ask FileHelpers questions, so I don't know what else someone is supposed to do. In any case, the project was completed and used in production quite successfully, so whatever it is I did (I don't even remember) worked fine. (It's a weird piece of software - will get brought out every 2 years, run for 7 - 10 days, then shelved.) – Walt Jul 25 '22 at 15:03