I have a console app which is self-hosting the ASP.Net WebAPI. I would like the console app to self terminate based on a specific call to the WebAPI.
The console app is heavily based on the example found here -> http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api
To provide some context;
The console app will be used in conjunction with Jenkins CI to automate BDD testing of an Android application. Jenkins will be responsible for building, installing and initiating an Android app - it will then invoke this console app. The Android app will run through a series of Jasmine BDD tests automatically returning updates to Jenkins via the console app/ WebAPI. On completion of the tests, the Android App will call a specific WebAPI action - at this point I want it to terminate the console app so that Jenkins will move onto the next build step.
Thanks in advance.
Just use a ManualResetEvent
. In your Program class, add a static public field:
public static System.Threading.ManualResetEvent shutDown =
new ManualResetEvent(false);
And then in your main method:
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
//Console.WriteLine("Press Enter to quit.");
//Console.ReadLine();
shutDown.WaitOne();
}
And then in the appropriate API method:
Program.shutDown.Set();
When your main method exits, the program will stop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With