Autor Beitrag
Necaremus
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 203
Erhaltene Danke: 18

Win > XP, Vista, 7; Android 2.1
C# > VS '08,'10; Delphi7
BeitragVerfasst: Mi 28.07.10 16:28 
huhu

ich wollte fragen, ob es möglich ist eine WindowsForm und ein service in ein und die selbe .exe zu packen?
also, dass wenn man die exe normal aufruft, er als Form startet, wenn man die aber übern service-manager startet, er den service startet.

Und falls es möglich ist: wie? :D


Danke schonmal im vorraus.

mfg
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mi 28.07.10 16:37 
Hallo,

du kannst in der Main-Methode einen Argument auswerten und dementsprechend als Window-Service oder als Prozess (Konsole/WinForms) starten.

Zum Beispiel:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
   public class NorthernLightInformerWindowsService : ServiceBase
    {
        private ServiceHost host;

        public static void Main(string[] args)
        {
            if (args.Length > 0 && args[0].ToLower() == "debug")
            {
                Console.WriteLine("Starte Server...");

                NorthernLightsInformerService.StartService();

                Console.WriteLine("Server läuft, bis Sie 'Return' drücken!");
                Console.ReadLine();
                NorthernLightsInformerService.StopService();
            }
            else
            {
                System.ServiceProcess.ServiceBase.Run(
                    new ServiceBase[] { new NorthernLightInformerWindowsService() });
            }
        }

        protected override void OnStart(string[] args)
        {
            host = new ServiceHost(typeof(NorthernLightsInformerService));
            host.Open();
        }

        protected override void OnStop()
        {
            host.Close();
        }
    }


Gruß