In last days, we’re developing different nuget packages to reduce development time of our employees

The TNX.ApplicationJobs is a NuGet package serie that enables developers to write immediate ConsoleApplication based micro job applications, easy to deploy and to maintain. Considering that each micro application focus on a single feature

A consoleapplication based job is easy to execute where-ever and easy to schedule/configure as a running job in an on-premise environment (windows scheduling, sql agent…)

Please install the NuGet packages:

  • TNX.ApplicationJobs.Common
  • TNX.ApplicationJobs.TcpListener

We focused this library package with the idea of shortening developent time and creating single-feature applications. Here the code to write a local Tcp listener on port 8080

class Program
     static void Main(string[] args) => new ConsoleApplication()
         .Listen(OnClientConnected8080, 8080)

    private static void OnClientConnected8080(Task<TcpClient> t)
         using (var client = t.Result)
         using (var stream = client.GetStream())
         using (var reader = new StreamReader(stream))
         using (var writer = new StreamWriter(stream))
             while (!reader.EndOfStream)
                 var row = “=> ” + reader.ReadLine();

I know. It is a very short code example. But the client communication implementation (the OnClientConnected8080 method) the application is only a single code line

The “new ConsoleApplication()” starts our console application job host environment

Continuing the understanding of the Job host (the ConsoleApplication class) the first method is Init(), this actually does

  • read args[] params to catch default command arguments as
    • -v: verbose
    • -forever: never exit (for TcpListener implementation always true)
    • – th:4: set the child message pump thread count (ignored for TcpListener implementation – very useful for messaged implementation with RabbitMQ or others)
  • configures Culture to Neutral
  • configures the service point defaut connection limit to 64
  • configures the Thread pool min (256) and max (short.MaxValue) values
  • obviously the ConsoleApplication is configurable via writable properties and inheritance to change the overall behavior

Later we invoke the Listen extension method that will generate child tasks within the job host each implementing the TcpListener listening standard logic with task/async support. You only have to specify a method able to catch the async TcpClient connection and the port number. Obviously it is possible to Listen mnultiple logics and multiple ports on a single listening

Stay tuned to get other features of the AplicationJobs nuget package serie

thanks for reading