Skip to content

Instantly share code, notes, and snippets.

@joshmarinacci
Created December 3, 2015 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmarinacci/942b3e7022a682e92894 to your computer and use it in GitHub Desktop.
Save joshmarinacci/942b3e7022a682e92894 to your computer and use it in GitHub Desktop.
protected override void OnStart(string[] args)
{
string[] imagePathArgs = Environment.GetCommandLineArgs();
if (imagePathArgs.Length >= 2)
{
int value = 0;
if (Int32.TryParse(imagePathArgs[1], out value)) MaxCPUUsage = value;
else
{
eventLog.WriteEntry("Fail to convert parameter 1:" + imagePathArgs[1]);
}
}
if (imagePathArgs.Length >= 3)
{
int value = 0;
if (Int32.TryParse(imagePathArgs[2], out value)) MinRAMAvailable = value;
else
{
eventLog.WriteEntry("Fail to convert parameter 2:" + imagePathArgs[2]);
}
}
if (imagePathArgs.Length >= 3)
{
int value = 0;
if (Int32.TryParse(imagePathArgs[3], out value)) Period = value;
else
{
eventLog.WriteEntry("Fail to convert parameter 3:" + imagePathArgs[3]);
}
}
eventLog.WriteEntry("MaxCPUUsage=" + MaxCPUUsage.ToString() + ", " + "MinRAMAvailable=" + MinRAMAvailable.ToString() + ", " + "Period=" + Period.ToString());
try
{
eventLog.WriteEntry("Subscribe channel " + channel);
mrePubNub = new ManualResetEvent(false);
pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeMethodForConnectCallback, ErrorCallback);
mrePubNub.WaitOne(manualResetEventsWaitTimeout);
eventLog.WriteEntry("Channel " + channel + " subscribed.");
trf = new Thread(new ThreadStart(Process));
trf.IsBackground = true;
trf.SetApartmentState(ApartmentState.MTA);
trf.Start();
}
catch (Exception erro)
{
eventLog.WriteEntry("Subscribe channel " + channel + "\r\n" + erro.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment