本文整理汇总了C#中System.ServiceProcess.ServiceBase类的典型用法代码示例。如果您正苦于以下问题:C# ServiceBase类的具体用法?C# ServiceBase怎么用?C# ServiceBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceBase类属于System.ServiceProcess命名空间,在下文中一共展示了ServiceBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 );
}
开发者ID:NewSpring,项目名称:Rock,代码行数:32,代码来源:Program.cs
示例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();
}
}
开发者ID:emmandeb,项目名称:ClearCanvas-1,代码行数:30,代码来源:Program.cs
示例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
}
开发者ID:norm472,项目名称:ParadoxAlarmControl,代码行数:30,代码来源:Program.cs
示例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
}
开发者ID:bmadarasz,项目名称:ndihelpdesk,代码行数:29,代码来源:Program.cs
示例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);
}
}
}
开发者ID:iamlos,项目名称:Seo.Crawler.Service,代码行数:31,代码来源:Program.cs
示例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);
}
开发者ID:rahulgarg1985,项目名称:CDMRS,代码行数:28,代码来源:Program.cs
示例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);
}
}
开发者ID:Alchemy86,项目名称:GD_BackOrders,代码行数:27,代码来源:Program.cs
示例8: HostService
public HostService(ServiceBase[] services)
{
this.Services = services;
InitializeComponent();
OnStartMethod = typeof(ServiceBase).GetMethod("OnStart", BindingFlags.NonPublic | BindingFlags.Instance);
}
开发者ID:dstimac,项目名称:revenj,代码行数:7,代码来源:HostService.cs
示例9: Run
public void Run()
{
_log.Debug("[Topshelf] Starting up as a windows service application");
var servicesToRun = new ServiceBase[] {this};
Run(servicesToRun);
}
开发者ID:SaintGimp,项目名称:Topshelf,代码行数:7,代码来源:ServiceHost.cs
示例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
}
开发者ID:sta99ot,项目名称:ffs,代码行数:31,代码来源:Program.cs
示例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();
}
}
}
开发者ID:Wryxo,项目名称:bakalarka,代码行数:28,代码来源:Program.cs
示例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;
}
}
开发者ID:nortal,项目名称:Utilities.TaskSchedulerEngine,代码行数:32,代码来源:Program.cs
示例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);
}
开发者ID:mcvladthegoat,项目名称:AnvizService,代码行数:32,代码来源:Program.cs
示例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);
}
开发者ID:kcitwm,项目名称:dova,代码行数:31,代码来源:Program.cs
示例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);
}
}
开发者ID:wfraser,项目名称:FooSync,代码行数:33,代码来源:Program.cs
示例16: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
if (args.Length > 0)
{
// Parse the command line args
var install = ParseCommandLine(args);
if (install == true)
{
InstallationManager.Install(args);
}
else if (install == false)
{
InstallationManager.Uninstall(args);
}
else
{
Trace.Listeners.Add(new ConsoleTraceListener());
Trace.WriteLine("Debugging press return to exit...");
var svc = new SyslogSharpService();
svc.Debug();
Console.ReadLine();
Trace.WriteLine("Finished.");
// Console.WriteLine("Invalid command line args -i for install or -u for uninstall");
}
}
else
{
var servicesToRun = new ServiceBase[] { new SyslogSharpService() };
ServiceBase.Run(servicesToRun);
}
}
开发者ID:hagenson,项目名称:SysLogSharp,代码行数:38,代码来源:Program.cs
示例17: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (args.Length > 0)
{
NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging(NLog.LogLevel.Debug);
if (args[0] == "-debug")
{
Debug(args);
}
else if (args[0] == "-testTask")
{
if (args.Length < 2) throw new Exception("Task file name missing");
TestTask(args[1]);
}
else if (args[0] == "-testJob")
{
if (args.Length < 2) throw new Exception("Job ID missing");
TestJob(args[1]);
}
else
{
Console.WriteLine("Invalid arguments specified.");
Console.WriteLine("Possible options: \n-debug\n-testTask [task json file]\n-testJob [jobId]");
}
return;
}
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
开发者ID:lafar6502,项目名称:cogmon,代码行数:37,代码来源:Program.cs
示例18: Main
static void Main(string[] args)
{
EnsureBuildNumberIsPutIntoSummaryFile();
Dictionary<string,string> arguments = StringUtilities.ParseCommandLine(args);
// If there is a -Service switch then start as a service otherwise start as a regular application
if (arguments.ContainsKey("-Service"))
{
int maximumNumberOfCores = -1;
if (arguments.ContainsKey("-MaximumNumberOfCores"))
maximumNumberOfCores = Convert.ToInt32(arguments["-MaximumNumberOfCores"]);
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new RunnerService(maximumNumberOfCores)
};
ServiceBase.Run(ServicesToRun);
}
else
{
if (!RunJobFromCommandLine(args))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(args));
}
}
}
开发者ID:APSIMInitiative,项目名称:APSIM.Cloud,代码行数:29,代码来源:Program.cs
示例19: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (args.Length > 0)
{
// Install service
if (args[0].Trim().ToLower() == "/i")
{
ManagedInstallerClass.InstallHelper(new string[] { "/i", Assembly.GetExecutingAssembly().Location });
return;
}
// Uninstall service
if (args[0].Trim().ToLower() == "/u")
{
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
return;
}
}
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ServiceOne(),
new ServiceTwo()
};
ServiceBase.Run(ServicesToRun);
}
开发者ID:frankfajardo,项目名称:.net-multiWinSvcTemplate,代码行数:30,代码来源:Program.cs
示例20: RunInteractive
//
// http://coding.abel.nu/2012/05/debugging-a-windows-service-project/
static void RunInteractive(ServiceBase[] servicesToRun)
{
Console.WriteLine("Services running in interactive mode.");
Console.WriteLine();
MethodInfo onStartMethod = typeof(ServiceBase).GetMethod("OnStart",
BindingFlags.Instance | BindingFlags.NonPublic);
foreach (ServiceBase service in servicesToRun)
{
Console.Write("Starting {0}...", service.ServiceName);
onStartMethod.Invoke(service, new object[] { new string[] { } });
Console.Write("Started");
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(
"Press any key to stop the services and end the process...");
Console.ReadKey();
Console.WriteLine();
MethodInfo onStopMethod = typeof(ServiceBase).GetMethod("OnStop",
BindingFlags.Instance | BindingFlags.NonPublic);
foreach (ServiceBase service in servicesToRun)
{
Console.Write("Stopping {0}...", service.ServiceName);
onStopMethod.Invoke(service, null);
Console.WriteLine("Stopped");
}
Console.WriteLine("All services stopped.");
// Keep the console alive for a second to allow the user to see the message.
Thread.Sleep(1000);
}
开发者ID:SavageLearning,项目名称:Machete,代码行数:36,代码来源:Program.cs
注:本文中的System.ServiceProcess.ServiceBase类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论