1

We have created a Event System which start on component save. Here in component save event handler we are applying few complex logic and making some changes in some text file.

As complexities are there and possibilities of dirty read can be there. We want to implement something which can force other treads to wait while

In other words is it possible to place all component save event in queue while one is going through.

2
  • By threads, do you mean changes to a single text file by different components? Or would each Component update its own text file? What do you use the text file for and does it need to be updated on each Component save? Other extension options include a Bundle and/or Workflow or maybe on publish, but it depends on what you need the text file for. Commented Jun 1, 2015 at 11:40
  • You may want to explore lock, Monitor and Mutex in C# instead of searching a solution in the SDL Tridion :) Commented Jun 1, 2015 at 11:48

3 Answers 3

3

For starters I would always advise against making changes in a text file from an event handler, since that forces the event handler to be single threaded, which causes issues on outscaling. The question also remains, why would you connect from a database driven system to something as rudimentary as a text file.

If you really must update a text file, then I suggest you write some code/application that can safely handle accessing that file, and implement the event handler on Component save asynchronously (so it has no influence on the actual save time) and then handle the queueing of the text file write actions yourself.

Don't expect Tridion to have a queue for your write actions available, and don't try to implement a queue in the event handler itself. Ideally you create a web service for the changes to your text file, and call that from the event handler, that way, if you need to outscale the SDL Tridion CM, you won't have any issues with finding and updating that certain text file. And in your web service you can implement a queue to safely handle concurrent writes.

1

Instead of using a text file, consider using App Data. This way you don't have to worry about synchronization. On component save, simply retrieve your text blob by key, do what you need to with it, and then write back.

I advise you to stay away from monitors and locks. This can cause system delays for all users, and in general, can produce unexpected/weird results.

0
0

As this is a generic C# multithreaded producer/consumer problem you might want to look there for a solution.

You can use a BlockingCollection as intermediary between your producers (your event system threads) and your consumer (a separately started thread that manages your text file).

When your event system starts up you create the BlockingCollection and start the consumer thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.