I’m currently working on a service (well at this point it’s still a Console Application, as this is a lot easier to debug). The basic task of this service is to watch a folder for new *.tif Files. As soon as the Application found a .TIF file in the folder it starts another Application with the following code:
ProcessStartInfo command = new ProcessStartInfo(commandPath, commandParams);
command.RedirectStandardOutput=true;
command.UseShellExecute=false;
command.CreateNoWindow=true;
Process process = new Process();
process.startInfo = command;
process.Start();
process.WaitForExit();
This console application then uses IrfanView to split the Multipage-TIF into multiple singlepage-TIF (I use basically the same code as above to do this). After that, I check for a Barcode on the Scanned image (with zxing library). The found Barcode is then compared to the Oracle Database. Afterwards the file is converted to PDF and moved to a specific location, based on the found Barcode.
This console Application works perfectly, when I start it myself, but as soon as the “service” starts it, it will pause after a while and don’t do anything until I close the “service”-console application. Then it finishes normally.
What could be the problem?
I tried to disable the Oracle, DB check and it worked. Afterwards I disabled my Logging class and it worked too. So my guess is, that I somehow use too much ressources or something like that. But where to start?
EDIT:
Some additional information. I just debugged the process, as VS is able to attach to a process to debug. The command that hangs is Console.WriteLine (called from within the Console application which is called by my “service” console. Any way that a console in a subprocess can only have a certain amount of lines/chars? can a console-output stream have a deadlock or what is this?
Ok, I found the answer to my problem. I specified that I want to RedirectStandardOutput on my ProcessStartInfo object. The problem is, that I only read the Output at the end of the execution of the console application, which caused a deadlock. It looks like the buffer can only hold 1024 characters (according to this post). As soon as you want to write more into that buffer, the Console.WriteLine waits. If you (like me) only read at the end of the execution of the console application, this buffer will never be cleared, so you got a really nice deadlock 😉
Hope this helps some other people! cheers