none
Formless app that doesn't show in the task bar RRS feed

  • Question

  • I need a desktop app to do some ad hoc background processing for other desktop apps. I want the app to be not visible anywhere, and I don't want a service. Being listed in the task manager is fine, but being shown on the task bar is not.

    A typical formless app would be:

    using System;
    
    namespace WindowsFormsApp1
    {
      static class Program
      {
        [STAThread]
        static void Main ()
        {
          /*
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new Form1());
          */
    
          [do stuff here]
        }
      }
    }
    
    How do I make this not appear in the task bar? If I don't use "Application.Run(new Form1())", do I actually need "[STAThread]"?

    Tuesday, February 6, 2018 9:56 AM

Answers

  • Normally is for what you ask never used a windows Forms application. 

    Be aware that if you don't ever show something, it does not come in the taskmanager at processes either (it is not complete invisible). However because of that users will see it already quick as a kind of virus. 

    A console application is the normal way, that starts, processes and stops without ever been seen if you prevent the showing of that. 


    Success Cor

    • Marked as answer by Dev10110110 Tuesday, February 6, 2018 12:32 PM
    Tuesday, February 6, 2018 11:33 AM
  • Just spawn a new Thread to do the actual work and you'll be fine.

    (We all experienced problem that having ghostly thread running in WinForm Applications so when the main form closes, the application does not exit).

    • Marked as answer by Dev10110110 Tuesday, February 6, 2018 2:16 PM
    Tuesday, February 6, 2018 1:35 PM
    Answerer

All replies

  • 1) Yup. Just take away the preset code in Main() and there will not be any icon visible on taskbar. You can replace it with something like System.Threading.Thread.Sleep(30000); to see the effect.

    Although I'd start with "Windows Service" project as start point because it'd contain far less dependency on the project.

    2) STAThread is not needed if 1) your program does not contain UI code at all; and 2) your code does not use any COM components that assumes STA apartment settings.


    Tuesday, February 6, 2018 10:20 AM
    Answerer
  • You can use a normal Form and

    private void Form1_Load(object sender, EventArgs e)
    {
        Visible = false;
        ShowInTaskbar = false;          
    }

    Tuesday, February 6, 2018 10:34 AM
  • @cheong00

    Thanks for the suggestion. It almost worked but not quite. Windows 10 showed hourglass-equivalent cursor while the app ran. This would be as undesirable as having the app shown in the taskbar. Essentially I need something that runs unobtrusively in the background. The reason I don't want a service is because I don't want the extra work on IPC, service maintenance, install, etc.

    @Castorix31

    Thanks for that. I already have something similar and hoped I could throw out some of the dead weight. If that's not possible, then your solution would be the best.

    Tuesday, February 6, 2018 10:51 AM
  • Normally is for what you ask never used a windows Forms application. 

    Be aware that if you don't ever show something, it does not come in the taskmanager at processes either (it is not complete invisible). However because of that users will see it already quick as a kind of virus. 

    A console application is the normal way, that starts, processes and stops without ever been seen if you prevent the showing of that. 


    Success Cor

    • Marked as answer by Dev10110110 Tuesday, February 6, 2018 12:32 PM
    Tuesday, February 6, 2018 11:33 AM
  • Normally is for what you ask never used a windows Forms application. 

    Be aware that if you don't ever show something, it does not come in the taskmanager at processes either (it is not complete invisible). However because of that users will see it already quick as a kind of virus. 

    A console application is the normal way, that starts, processes and stops without ever been seen if you prevent the showing of that. 


    Success Cor

    My App shows up in virus scans all the time, lots of people just don't care :) It's not so much that it's a virus, the scanners are bad. Imagine that: a call to 32 bit fopen() is a virus! Some of these virus merchants are just too greedy or too desperate.

    Your idea of this console app is very interesting. How do I prevent the DOS window appearing while the app runs ?


    • Edited by Dev10110110 Tuesday, February 6, 2018 12:08 PM
    Tuesday, February 6, 2018 12:07 PM
  • Many thanks Cor Ligthert, your suggestion lead to the following solution. I haven't tried it yet, but looks good.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/16b5aff3-2aff-4434-a3d7-bc5048f66572/how-to-make-a-console-apps-window-invisible?forum=csharpgeneral


    • Edited by Dev10110110 Tuesday, February 6, 2018 12:33 PM
    Tuesday, February 6, 2018 12:32 PM
  • Yea, 

    I was as well strugling with it. But in fact a C# WPF and Windows Forms application start as well with a console application. That lead l to this solution Mathew gave too.


    Success Cor


    Tuesday, February 6, 2018 12:35 PM
  • Cor Ligthert,

    From what you said earlier, I am getting the impression that I can hide the app from the task manger too? Have I misunderstood?

    I would be very interested in that if possible, as an excellent cracking defence against script kiddies.




    • Edited by Dev10110110 Tuesday, February 6, 2018 12:46 PM
    Tuesday, February 6, 2018 12:44 PM
  • Just spawn a new Thread to do the actual work and you'll be fine.

    (We all experienced problem that having ghostly thread running in WinForm Applications so when the main form closes, the application does not exit).

    • Marked as answer by Dev10110110 Tuesday, February 6, 2018 2:16 PM
    Tuesday, February 6, 2018 1:35 PM
    Answerer
  • Many thanks cheong00. I can see how that will work. But I am worried windows will treat orphaned threads as special and terminate them in unknown conditions. May be I am just scaring myself. Surely, MS wouldn't kill orphans!

    Good stuff.

    Tuesday, February 6, 2018 2:16 PM