Gerneio Gerneio - 2 months ago 21
C# Question

Azure Web Jobs failure - ReadLine() left in

So I created an Azure Web Job that performs a certain task every 15 mins. It runs a C# console application. The problem is that on my last upload of my program I left my

Console.ReadLine();
argument in, causing the program to never finish (used for local debugging of course) and the web job to fail and never run again. This can obviously be fixed real quick if I had the source code, but the source code is at my office, which I forgot to upload to my cloud storage. I won't have access to it till a bit later on this week.

So I'm looking for a quick fix. I can download the .exe program that was last uploaded easily. So now what I'm thinking is to run another program first that calls my main program and then closes it after a certain time. I tried a simple .bat script that was able to successfully open the program, but it couldn't close/kill the process due to access denied errors (worked locally). Any other quick suggestions that'll work in a web job environment?

Obviously if you see this here in a few days, I've probably already made corrections to the source code at the root of the issue, but others may be interested as well. :)

UPDATE:

Thank you to everyone! Each of these solutions helped me to get my web job running as intended. The decompiling using Reflector was especially useful so that I can add this project to the cloud like its suppose to be. However, using the run.cmd as suggested by @evilSnobu was the easiest and simplest way to apply a workaround as requested in my question.

Again thank you! :)

P.S. I switched from
Console.ReadLine()
; to
System.Threading.Thread.Sleep();
to prevent any future mishaps.

Answer
public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Hello World!");
            Console.ReadLine();
            Console.WriteLine("After ReadLine");
        }
    }

Try running your Webjob as echo '\n' | helloconsole.exe

Testing in Kudu:

D:\home\tmp>echo '\n' | helloconsole.exe
Hello World!
After ReadLine

D:\home\tmp>echo '\n' | helloconsole.exe
Hello World!
After ReadLine

..seems to pull it off.

If you drop that in run.cmd it will have precedence over your .exe binary. https://github.com/projectkudu/kudu/wiki/Web-jobs

We use the following logic to decide which file is the script to run within the job's directory:

  • Per file type we look first for a file named: run.{file type extension} (for example run.cmd or run.exe).
Comments