views:

95

answers:

1
+2  Q: 

Timers in Services

Hi all,

we have recently added a new feature to our software - preview generation for documents that are uploaded and stored on the server. We did this the following way:

  1. The user uploads a document;
  2. Once the user opens the document information card, the preview for the recently uploaded document is issued (the info regarding the preview generation is stored in a db table);
  3. Every 30 seconds our service starts, reviews the preview table and initiates the preview generation procedures.

The problem that I am facing now is this - the new code for generating previews uses some of our legacy code and it sometimes "freezes" the Word or Excel processes. The generation of preview stops and all the following previews stay in "pending" mode until I kill the Word, Excel processes (we test the preview for MS Office documents). After I kill the processes, preview generation continues on.

I was thinking of implementing timers into our service so that if a service is awaiting for more that 1 minute after the preview generation has been started, it should kill the process and continue on with generating previews for other documents.

The main problem that I have is that i can not "move" the calls to our legacy code to separate processes as we have done with other documents (for example, we have implemented .ps file generation with GhostScript via Process'es).

Any ideas on how to "processify" the calls to legacy code?

+2  A: 

Can you make a second process which is a watchdog on the first process?

Or can you make the first process auto-restart, and have a second timer thread that monitors it and then kills its own process?

lavinio
The auto-restart seems to be quite complicated. I should probably try out the watch-dog approach. Maybe you have some code samples in C#?
fixed
I don't have code I can share, sorry. The way it works though is you start your service, and it starts the watchdog, passing it's own process ID to the watchdog so the latter knows where to look.
lavinio
We decided to implement the watch-dog style service to watch over the other process. Thank you!
fixed