本文整理汇总了C#中System.ServiceProcess.ServiceBase类的典型用法代码示例。如果您正苦于以下问题:C# ServiceBase类的具体用法?C# ServiceBase怎么用?C# ServiceBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceBase类属于System.ServiceProcess命名空间,在下文中一共展示了ServiceBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
string serviceFolder = Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location );
SqlServerTypes.Utilities.LoadNativeAssemblies( serviceFolder );
System.Diagnostics.Debugger.Launch();
RockMemoryCache.Clear();
// set the current directory to the same as the current exe so that we can find the web.connectionstrings.config
Directory.SetCurrentDirectory( serviceFolder );
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new JobScheduler()
};
//// NOTE: To run and debug this service in Visual Studio uncomment out the debug code below
//// Make sure you have a web.connectionstring.config in your debug/bin directory!
//JobScheduler debug = new JobScheduler();
//debug.StartJobScheduler();
// if you'd rather debug the app running as an actual service do the following:
// 1. Install the app as a service 'installutil <yourproject>.exe' (installutil is found C:\Windows\Microsoft.NET\Framework64\v4.0.30319\)
// 2. Add the line System.Diagnostics.Debugger.Launch(); where you'd like to debug
//
// Note: to uninstall the service run 'installutil /u <yourproject>.exe'
//System.Diagnostics.Debugger.Launch();
ServiceBase.Run( ServicesToRun );
}
示例2: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
var commandLine = new CommandLine(args);
if (commandLine.RunAsService)
{
var ServicesToRun = new ServiceBase[] { new ShredHostService() };
ServiceBase.Run(ServicesToRun);
}
else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename))
{
var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups();
groups.Add(new SettingsGroupDescriptor(typeof (ShredSettingsMigrator).Assembly.GetType("ClearCanvas.Server.ShredHost.ShredHostServiceSettings")));
foreach (var group in groups)
SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename);
}
else
{
ShredHostService.InternalStart();
Console.WriteLine("Press <Enter> to terminate the ShredHost.");
Console.WriteLine();
Console.ReadLine();
ShredHostService.InternalStop();
}
}
示例3: Main
static void Main()
{
#if DEBUG
try
{
ServiceStartup.Run();
Console.WriteLine("Press <CTRL>+C to stop.");
SetConsoleCtrlHandler(ConsoleCtrlCheck, true);
Thread.Sleep(Timeout.Infinite);
}
catch (Exception ex)
{
Console.WriteLine("ERROR: {0}: {1}", ex.GetType().Name, ex.Message);
throw;
}
finally
{
ServiceStartup.Stop();
}
#else
var appHost = ServiceStartup.GetAppHostListner();
var servicesToRun = new ServiceBase[]
{
new WinService(appHost, ServiceStartup.ListeningOn)
};
ServiceBase.Run(servicesToRun);
#endif
}
示例4: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
#if (!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new TimerService()
};
ServiceBase.Run(ServicesToRun);
#else
//// Debug code: this allows the process to run as a non-service.
//// It will kick off the service start point, but never kill it.
//// Shut down the debugger to exit
TimerService service = new TimerService();
service.StartService(false, false, true);
//// Put a breakpoint on the following line to always catch
//// your service when it has finished its work
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#endif
}
示例5: Main
static void Main()
{
if (!Environment.UserInteractive)
{
// Startup as service.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
else
{
// Startup as application
try
{
var options = System.Configuration.ConfigurationManager.GetSection("CrawlerOptions") as CrawlerOptions;
logger.Info("Config is {0}", options);
var crawler = new Crawler(options);
crawler.Start();
}
catch (Exception ex)
{
logger.Fatal(ex);
}
}
}
示例6: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
private static void Main()
{
//#if DEBUG
// //If the mode is in debugging
// //create a new service instance
// var myService = new MonitoringUnit();
// //call the start method - this will start the Timer.
// myService.Start();
// //Set the Thread to sleep
// Thread.Sleep(1000000000);
// Console.Read();
//#else
//var servicesToRun = new ServiceBase[]
//{
// new MonitoringUnit()
//};
//ServiceBase.Run(servicesToRun);
//#endif
var servicesToRun = new ServiceBase[]
{
new MonitoringUnit()
};
ServiceBase.Run(servicesToRun);
}
示例7: Main
private static void Main()
{
try
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#if DEBUG
var s = new Service1();
new Error().Add("moo");
s.OnDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
#endif
}
catch (Exception e)
{
var message =
e.Message + Environment.NewLine + e.Source + Environment.NewLine + e.StackTrace
+ Environment.NewLine + e.InnerException;
new Error().Add(message);
}
}
示例8: HostService
public HostService(ServiceBase[] services)
{
this.Services = services;
InitializeComponent();
OnStartMethod = typeof(ServiceBase).GetMethod("OnStart", BindingFlags.NonPublic | BindingFlags.Instance);
}
示例9: Run
public void Run()
{
_log.Debug("[Topshelf] Starting up as a windows service application");
var servicesToRun = new ServiceBase[] {this};
Run(servicesToRun);
}
示例10: Main
static void Main(string[] args)
{
#if Service
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new HttpService()
};
ServiceBase.Run(ServicesToRun);
#else
Console.BufferWidth = 120;
Console.BufferHeight = 1024;
StaticServerStuff.args = args;
StaticServerStuff.Init();
while (true)
{
Console.Write("\r" + StaticServerStuff.promt);
try
{
StaticServerStuff.ProcessCommand(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endif
}
示例11: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (args.Length == 0)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SetItUpService()
};
ServiceBase.Run(ServicesToRun);
}
else if (args.Length == 1)
{
if (args[0] == "install")
{
InstallService();
StartService();
}
if (args[0] == "uninstall")
{
StopService();
UninstallService();
}
}
}
示例12: Main
static void Main(string[] args)
{
try
{
// service that contains a single engine which automatically discovers ISchedulerTask implementations
var service = new SingleSchedulerEngineExecutionService<AllHostTasksSchedulerEngine>("MyTaskSchedulerService");
// to manually control included ISchedulerTasks, create your own engine by inheriting from SchedulerEngine.
// to have more engines running concurrently, create your own scheduler engine executor by inheriting from SchedulerEngineExecutionServiceBase
//runnning the service as any other windows service:
if (Environment.UserInteractive)
{
Console.WriteLine("Starting ExampleService in command-line mode ..");
Console.WriteLine("Press CTRL-C to terminate ..");
service.Start();
Console.ReadLine();
service.Stop();
}
else
{
var ServicesToRun = new ServiceBase[] { service };
ServiceBase.Run(ServicesToRun);
}
}
catch (Exception exception)
{
Debugger.Break();
throw;
}
}
示例13: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
String[] myargs = Environment.GetCommandLineArgs();
if (myargs.Length > 1)
{
String arg = myargs[1].ToLower();
if ((arg == "-install") || (arg == "-i"))
{
String[] args = new String[1];
args[0] = Assembly.GetExecutingAssembly().Location;
ExecuteInstallUtil(args);
}
if ((arg == "-uninstall") || (arg == "-u"))
{
String[] args = new String[2];
args[0] = Assembly.GetExecutingAssembly().Location;
args[1] = "-u";
ExecuteInstallUtil(args);
}
return;
}
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new AnvizService()
};
ServiceBase.Run(ServicesToRun);
}
示例14: Main
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
int type = ServiceConfigs.ServiceType;
ServiceBase[] ServicesToRun = null;
if (type == 1)
{
ServicesToRun = new ServiceBase[]
{
new SyncMessageService()
};
}
//else if (type == 2)
//{
// ServicesToRun = new ServiceBase[]
// {
// new MQConsumerService()
// };
//}
//else
//{
// ServicesToRun = new ServiceBase[]
// {
// new SyncMessageService(),
// new MQConsumerService()
// };
//}
ServiceBase.Run(ServicesToRun);
}
示例15: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
if (Type.GetType("Mono.Runtime") != null // mono-service2 sucks; run as foreground process instead
#if DEBUG
|| Debugger.IsAttached
#endif
)
{
try
{
var svc = new FooSyncService();
var args = Environment.GetCommandLineArgs();
svc.Start(args.Where((arg, index) => index > 0).ToArray());
}
catch (Exception ex)
{
Console.WriteLine("Unhandled {0}: {1}", ex.GetType().Name, ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new FooSyncService()
};
ServiceBase.Run(ServicesToRun);
}
}