none
Hidden background process RRS feed

  • Question

  • I need to make a invisible background process which monitor some process is running or terminated.

    The console application has a console window and WinForm does as well.

    Should I make it WinForm with Visible = false?

    Can anybody give me some advice about what is the best way.

    Saturday, March 28, 2020 6:39 PM

Answers

  • Hi Jeff,

    I recommend you need to create a windows service app,because you no need any user interface or making hidden WinForm this link helps you to better understand of Windows service.

    https://docs.microsoft.com/en-us/dotnet/framework/windows-services/introduction-to-windows-service-applications


    https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer


    Please remember to mark the replies as answers if they helped you :) ~


    • Edited by Rebin Qadir Saturday, March 28, 2020 8:32 PM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:30 AM
    Saturday, March 28, 2020 8:31 PM
  • Maybe create a Forms application, open the Program.cs file, remove the contents of Main function and replace it with your code. Remove the unneeded Form1.


    • Edited by Viorel_MVP Saturday, March 28, 2020 8:34 PM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 8:33 PM
  • I need to make a invisible background process which monitor some process is running or terminated.

    The console application has a console window and WinForm does as well.

    Should I make it WinForm with Visible = false?

    Can anybody give me some advice about what is the best way.

    You could create a C# console project.  In the project properties, change the output type from Console Application to Windows Application.

    Now a console will not be created and there are no forms to deal with.

    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 8:35 PM
  • I see two good choices, the first is to create a tray app which is done using a NotifyIcon component which will run in the windows tray, see documentation and example. Using a tray app the app has the same rights as the login user while a windows service has less rights and is more work to install and uninstall. Also debugging a windows service is easy to debug on Windows 7 while starting with Windows 8 onwards the windows team implemented stronger security which requires extra steps to debug, see my TechNet article With a tray app you can but don't need a user interface, any interaction can be done via a Context menu.

    The second choice is what RLWA32 suggested while this is a good choice too but lacks any control over stopping or interacting with the app at runtime.

    My recommendation is a tray app, here are my code samples.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:26 AM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 10:30 PM
    Moderator

All replies

  • Hi Jeff,

    I recommend you need to create a windows service app,because you no need any user interface or making hidden WinForm this link helps you to better understand of Windows service.

    https://docs.microsoft.com/en-us/dotnet/framework/windows-services/introduction-to-windows-service-applications


    https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer


    Please remember to mark the replies as answers if they helped you :) ~


    • Edited by Rebin Qadir Saturday, March 28, 2020 8:32 PM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:30 AM
    Saturday, March 28, 2020 8:31 PM
  • Maybe create a Forms application, open the Program.cs file, remove the contents of Main function and replace it with your code. Remove the unneeded Form1.


    • Edited by Viorel_MVP Saturday, March 28, 2020 8:34 PM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 8:33 PM
  • I need to make a invisible background process which monitor some process is running or terminated.

    The console application has a console window and WinForm does as well.

    Should I make it WinForm with Visible = false?

    Can anybody give me some advice about what is the best way.

    You could create a C# console project.  In the project properties, change the output type from Console Application to Windows Application.

    Now a console will not be created and there are no forms to deal with.

    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 8:35 PM
  • I see two good choices, the first is to create a tray app which is done using a NotifyIcon component which will run in the windows tray, see documentation and example. Using a tray app the app has the same rights as the login user while a windows service has less rights and is more work to install and uninstall. Also debugging a windows service is easy to debug on Windows 7 while starting with Windows 8 onwards the windows team implemented stronger security which requires extra steps to debug, see my TechNet article With a tray app you can but don't need a user interface, any interaction can be done via a Context menu.

    The second choice is what RLWA32 suggested while this is a good choice too but lacks any control over stopping or interacting with the app at runtime.

    My recommendation is a tray app, here are my code samples.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Naomi NModerator Sunday, March 29, 2020 2:26 AM
    • Marked as answer by Jeff0803 Sunday, March 29, 2020 3:29 AM
    Saturday, March 28, 2020 10:30 PM
    Moderator