本文整理汇总了C#中ServiceController.Start方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.Start方法的具体用法?C# ServiceController.Start怎么用?C# ServiceController.Start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceController
的用法示例。
在下文中一共展示了ServiceController.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnAfterInstall
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
ServiceConfigurator.SetRecoveryOptions(ServiceName());
using (ServiceController pc = new ServiceController(ServiceName()))
{
pc.Start();
}
}
示例2: TestExceptionLogged
public void TestExceptionLogged()
{
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockNonSerializableServiceLoaderProxy)
};
service.Start();
Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles());
Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0);
service.Dispose();
}
示例3: Main
static void Main()
{
ServiceController myservice = new ServiceController();
myservice.ServiceName = "Marimba";
string svcname = myservice.Status.ToString();
if(svcname.Equals("Running"))
{
Console.WriteLine("Service is Running");
Console.WriteLine("Stop Services");
myservice.Stop();
Console.WriteLine("Service Stopped");
}
else
{
Console.WriteLine("Starting service");
myservice.Start();
}
}
示例4: TestMethodCalledArguments
public void TestMethodCalledArguments()
{
var service = new ServiceController() {
Arguments = new List<String>() {
"A",
"B"
},
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
};
service.Start();
Assert.AreEqual(service.Arguments, ((MockServiceLoaderProxy)service.ServiceLoaderProxy).OnParseCommandLineArguments);
service.Dispose();
}
示例5: StopAndStart
public void StopAndStart()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
for (int i = 0; i < 2; i++)
{
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
controller.Start();
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
}
}
示例6: StartWithArguments
public void StartWithArguments()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
var args = new[] { "a", "b", "c", "d", "e" };
controller.Start(args);
controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
Assert.Equal(ServiceControllerStatus.Running, controller.Status);
// The test service writes the arguments that it was started with to the _testService.TestServiceRegistryKey.
// Read this key to verify that the arguments were properly passed to the service.
string argsString = Registry.GetValue(_testService.TestServiceRegistryKey, "ServiceArguments", null) as string;
Assert.Equal(string.Join(",", args), argsString);
}
示例7: Main
public static void Main(string[] args)
{
Thread.CurrentThread.Name = "MPMain";
#if !DEBUG
// TODO: work on the handlers to take over more Watchdog capabilities, current use for Area51 builds as needed only
//AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
//Application.ThreadException += OnThreadException;
#endif
SkinOverride = string.Empty;
WindowedOverride = false;
FullscreenOverride = false;
ScreenNumberOverride = -1;
if (args.Length > 0)
{
foreach (string arg in args)
{
if (arg == "/fullscreen")
{
FullscreenOverride = true;
}
if (arg == "/windowed")
{
WindowedOverride = true;
}
if (arg.StartsWith("/fullscreen="))
{
string argValue = arg.Remove(0, 12); // remove /?= from the argument
FullscreenOverride |= argValue != "no";
WindowedOverride |= argValue.Equals("no");
}
if (arg == "/crashtest")
{
_mpCrashed = true;
}
if (arg.StartsWith("/screen="))
{
string screenarg = arg.Remove(0, 8); // remove /?= from the argument
if (!int.TryParse(screenarg, out ScreenNumberOverride))
{
ScreenNumberOverride = -1;
}
}
if (arg.StartsWith("/skin="))
{
string skinOverrideArg = arg.Remove(0, 6); // remove /?= from the argument
SkinOverride = skinOverrideArg;
}
if (arg.StartsWith("/config="))
{
_alternateConfig = arg.Remove(0, 8); // remove /?= from the argument
if (!Path.IsPathRooted(_alternateConfig))
{
_alternateConfig = Config.GetFile(Config.Dir.Config, _alternateConfig);
}
}
if (arg.StartsWith("/safelist="))
{
_safePluginsList = arg.Remove(0, 10); // remove /?= from the argument
}
#if !DEBUG
_avoidVersionChecking = arg.ToLowerInvariant() == "/avoidversioncheck";
#endif
}
}
// check if MediaPotal is already running
using (var processLock = new ProcessLock(MPMutex))
{
if (processLock.AlreadyExists)
{
Log.Warn("Main: MediaPortal is already running");
Win32API.ActivatePreviousInstance();
}
}
if (string.IsNullOrEmpty(_alternateConfig))
{
Log.BackupLogFiles();
}
else
{
if (File.Exists(_alternateConfig))
{
try
{
MPSettings.ConfigPathName = _alternateConfig;
Log.BackupLogFiles();
Log.Info("Using alternate configuration file: {0}", MPSettings.ConfigPathName);
}
//.........这里部分代码省略.........
示例8: Main
public static void Main(string[] args)
{
Thread.CurrentThread.Name = "MPMain";
if (args.Length > 0)
{
foreach (string arg in args)
{
if (arg == "/fullscreen")
{
_fullscreenOverride = true;
}
if (arg == "/windowed")
{
_windowedOverride = true;
}
if (arg.StartsWith("/fullscreen="))
{
string argValue = arg.Remove(0, 12); // remove /?= from the argument
_fullscreenOverride |= argValue != "no";
_windowedOverride |= argValue.Equals("no");
}
if (arg == "/crashtest")
{
_mpCrashed = true;
}
if (arg.StartsWith("/screen="))
{
GUIGraphicsContext._useScreenSelector = true;
string screenarg = arg.Remove(0, 8); // remove /?= from the argument
if (!int.TryParse(screenarg, out _screenNumberOverride))
{
_screenNumberOverride = -1;
}
}
if (arg.StartsWith("/skin="))
{
string skinOverrideArg = arg.Remove(0, 6); // remove /?= from the argument
_strSkinOverride = skinOverrideArg;
}
if (arg.StartsWith("/config="))
{
_alternateConfig = arg.Remove(0, 8); // remove /?= from the argument
if (!Path.IsPathRooted(_alternateConfig))
{
_alternateConfig = Config.GetFile(Config.Dir.Config, _alternateConfig);
}
}
if (arg.StartsWith("/safelist="))
{
_safePluginsList = arg.Remove(0, 10); // remove /?= from the argument
}
#if !DEBUG
_avoidVersionChecking = false;
if (arg.ToLowerInvariant() == "/avoidversioncheck")
{
_avoidVersionChecking = true;
Log.Warn("Version check is disabled by command line switch \"/avoidVersionCheck\"");
}
#endif
}
}
if (string.IsNullOrEmpty(_alternateConfig))
{
Log.BackupLogFiles();
}
else
{
if (File.Exists(_alternateConfig))
{
try
{
MPSettings.ConfigPathName = _alternateConfig;
Log.BackupLogFiles();
Log.Info("Using alternate configuration file: {0}", MPSettings.ConfigPathName);
}
catch (Exception ex)
{
Log.BackupLogFiles();
Log.Error("Failed to change to alternate configuration file:");
Log.Error(ex);
}
}
else
{
Log.BackupLogFiles();
Log.Info("Alternative configuration file was specified but the file was not found: '{0}'", _alternateConfig);
Log.Info("Using default configuration file instead.");
}
}
if (!Config.DirsFileUpdateDetected)
{
//check if mediaportal has been configured
FileInfo fi = new FileInfo(MPSettings.ConfigPathName);
if (!File.Exists(MPSettings.ConfigPathName) || (fi.Length < 10000))
{
//no, then start configuration.exe in wizard form
Log.Info("MediaPortal.xml not found. Launching configuration tool and exiting...");
//.........这里部分代码省略.........
示例9: RestartC2RSerivce
public static void RestartC2RSerivce()
{
const string serviceName = "ClickToRunSvc";
var service = new ServiceController(serviceName);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 5));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 5));
}
示例10: Start_NullArg_ThrowsArgumentNullException
public void Start_NullArg_ThrowsArgumentNullException()
{
var controller = new ServiceController(_testService.TestServiceName);
Assert.Throws<ArgumentNullException>("args[0]", () => controller.Start(new string[] { null } ));
}
示例11: TestResultMessageProcessed
public void TestResultMessageProcessed()
{
var signaled = false;
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy),
SignalResult = (controller, message) => signaled = true
};
service.Start();
((MockServiceLoaderProxy)service.ServiceLoaderProxy).ExecuteResultMessage = new ServiceMessage() {
Name = "result"
};
service.ExecuteMessage(new ServiceMessage());
Assert.IsTrue(signaled);
service.Dispose();
}
示例12: TestMethodCalledCreate
public void TestMethodCalledCreate()
{
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
};
service.Start();
Assert.IsTrue(((MockServiceLoaderProxy)service.ServiceLoaderProxy).OnCreate);
service.Dispose();
}
示例13: TestStartIgnoredOnNonStoppedStatus
public void TestStartIgnoredOnNonStoppedStatus()
{
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy),
Observer = {
Status = ServiceStatusType.Started
}
};
service.Start();
Assert.IsNull(service.ServiceDomain);
service.Dispose();
}
示例14: TestServiceDomainCreated
public void TestServiceDomainCreated()
{
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
};
service.Start();
Assert.IsNotNull(service.ServiceDomain);
service.Dispose();
}
示例15: TestObservableStarted
public void TestObservableStarted()
{
var service = new ServiceController() {
Packages = new MockServicePackageManager(),
Settings = {
ServiceUpdateCore = false
},
ServiceLoaderProxyType = typeof(MockServiceLoaderProxy)
};
service.Start();
Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status);
service.Dispose();
}