Comparing Windows service and Windows application for Port reading application in Net

0 votes
I am writing a TCP/IP port reading application in .Net to read the data from IOT devices, currently it is running as a Windows application. I want to make it a Windows service, is there a better option? I want to read the ports 24/7. Is there any better options than a Windows service?
Aug 23, 2018 in IoT (Internet of Things) by Matt
• 2,270 points
598 views

1 answer to this question.

0 votes

If you want to be able to run the program with no user logged on, then a windows service is the way to go. If you want some graphical user interface, a normal application is more useful.

As a side node, you can change an application with debug-flags between starting as a service and starting as an application. Add a Service-Class to your app and another class for your custom code. The service will also call the Sample class. Then you can switch between using each during debug if you add a precompiler #if DEBUG in the Program.cs

    public static void Main()
    {
#if DEBUG
        SampleClass sc = new SampleClass();
        sc.Start();
#else
        ServiceBase[] servicesToRun = new ServiceBase[]
        {
            new SampleService ()
        };
        ServiceBase.Run(servicesToRun);
#endif
    }

then you can also add code for output that works differently for each build-type

    public static void WriteLog(string message, LogLevel logLevel)
    {
#if DEBUG
            Console.WriteLine(message);
#else
            Trace.Write ($"{DateTime.Now:dd.MM.yyyy HH:mm:ss.fff} {message}");
#endif
    }

Then if you start the app choose between build and debug. But you can only install the release-build as service this way.

answered Aug 23, 2018 by anonymous2
• 4,280 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

CLI for Watson IBM IoT service in Bluemix

Programmatically register devices using bulk/devices operations. https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_add Here's ...READ MORE

answered Nov 23, 2018 in IoT (Internet of Things) by DataKing99
• 8,240 points
601 views
0 votes
1 answer

Disk Management Commands in PowerShell for Windows IoT device

All libraries of the full .Net framework ...READ MORE

answered Nov 26, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
874 views
0 votes
1 answer

Data Modelling for IoT based application in Apache Cassandra

I think creating a single table that has ...READ MORE

answered Dec 4, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,520 views
0 votes
1 answer

.NET Core on Raspbian/ARM?

.NET Core 2.1 supports Raspberry Pi. Here is ...READ MORE

answered Aug 31, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
764 views
0 votes
1 answer

Naming my deployed application

Look in your Package.appxmanifest -- the name ...READ MORE

answered Sep 10, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
340 views
0 votes
1 answer

Display random images from USB on Raspberry Pi

Hey, it's a cool idea! And, since ...READ MORE

answered Nov 28, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,021 views
+1 vote
1 answer

RegEx to remove XML tags and their content

I presume you want to drop the ...READ MORE

answered Feb 13, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
5,809 views
0 votes
1 answer
0 votes
1 answer

How to get Unicast, Dns and Gateway Address in UWP?

Try this code Snippet I found here: https://social.msdn.microsoft.com/Forums/en-US/27a8b7a8-8071-4bc1-bbd4-e7c1fc2bd8d7/windows-10-iot-core-how-do-you-create-a-tcp-server-and-client?forum=WindowsIoT ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
984 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP