0

I've created a WinService, unfortunately Win7 (and Vista) does not support Screen Capture from a service. I'm going to rewrite a program into something different than WinService, something that has no forms..

what will you suggest?

  • Console Application has a console - I don't need any.
  • WinForms app has a form - I don't need any.

Is it possible to remove a form from winforms application completely? I don't want to hide a proccess or anything, but I want it to work as a listener on the background (just like a service).

How will I close it? Easy! An alternative to "Stop service" should be "End task" from task manager.

  • having no physical form and no focus is crucial condition.

EDIT:

thanks for the link! So I've removed form.cs completely, and made following changes to program.cs:

static class Program
{
    static Thread workerThread;

    [STAThread]
    static void Main()
    {
        //Application.EnableVisualStyles();
        //Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());

        load();
        workerThread.Start();
    }

    public static void load()
    {
        workerThread = new Thread(DoWork);
        workerThread.SetApartmentState(ApartmentState.STA);
    }

    static void DoWork()
    {
        while (true)
        {
            string directory = (@"C:\10\new\"); string name = (".bmp");
            string filename = String.Format("{0:hh-mm-ss}{1}", DateTime.Now, name);
            string path = Path.Combine(directory, filename);

            Bitmap bmp = new Bitmap(@"C:\10\1.bmp");
            bmp.Save(path);
            bmp.Dispose();
            Thread.Sleep(1100);
        }
    } 

do I need to make some other changes or it's ok as it is? I don't want my app to steal focus.. just a process must present.

  • is "Application.Run();" needed?
  • does this app has icon?
Alex
  • 4,607
  • 9
  • 61
  • 99

1 Answers1

2

You could create a console app and change it to be a Windows Form in VS. Then there won't be any console, just the process in task manager, but interaction with the desktop won't be restricted.

Bali C
  • 30,582
  • 35
  • 123
  • 152
  • "and change it to be a Windows Form in VS": do you mean to change "Output type: Windows Application" ? how will it be different than what I have right now? (see edit) – Alex Apr 13 '12 at 13:12
  • seems like one of the advantages is that I can switch to Console every time I need to debug my app.. anything else maybe? – Alex Apr 13 '12 at 13:21
  • @Alex Sorry I should have been more clear, yeah, change the output type. Your code looks fine from what I can see, but the advantages are that you can debug it easier as you mentioned. Its easier to manage and run and it shows in task manager and is allowed to interact with the desktop, which I think meets all of your requirements. – Bali C Apr 13 '12 at 13:37
  • ok, I'll be sticking with your method for the time being.. I've made some testing and everything works just fine. Thanks for the tips! – Alex Apr 13 '12 at 13:45