本文整理汇总了C#中IScheduler.Register方法的典型用法代码示例。如果您正苦于以下问题:C# IScheduler.Register方法的具体用法?C# IScheduler.Register怎么用?C# IScheduler.Register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScheduler
的用法示例。
在下文中一共展示了IScheduler.Register方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
public void Open(int timeout)
{
//已OPEN的,不再OPEN,多线程处理
if (IsHasOpen) return;
if (ConfigUtil.Instance.ConnectionCount > 0)
ServicePointManager.DefaultConnectionLimit = ConfigUtil.Instance.ConnectionCount;
ConfigUtil.Instance.NotifyPropertyChange += (type) =>
{
switch (type)
{
case NotifyProperty.ConnectionCount:
if (ConfigUtil.Instance.ConnectionCount > 0)
ServicePointManager.DefaultConnectionLimit =
ConfigUtil.Instance.ConnectionCount;
break;
default:
break;
}
};
if (IsNoExistFxConfig)
{
IDictionary<string, string> settings = SettingsUtils.GetAppSettings();
string configServiceUri = "";
if (settings.ContainsKey("CmessageServiceUri"))
configServiceUri = settings["CmessageServiceUri"];
if (string.IsNullOrEmpty(configServiceUri))
{
throw new Exception("Must config 'CmessageServiceUri' OR 'FxConfigServiceUrl' in appSettings.");
}
}
if(SyncScheduler==null)
{
SyncScheduler = ObjectFactory.Current.Get<IScheduler>(Lifetime.ContainerControlled);
SyncScheduler.Register(SyncServers, "cmessaging.producer.defaultmessagechannel.syncconfig", 60 * 1000, false);
}
if(!IsNoExistFxConfig)
{
ConfigUtil.Instance.RunScheduler();//v1.0启动同步
}
}
示例2: RunScheduler
public void RunScheduler()
{
if (SyncMetadataScheduler != null) return;
SyncMetadataScheduler = ObjectFactory.Current.Get<IScheduler>(Lifetime.ContainerControlled);
//每隔一分钟刷新一次
SyncMetadataScheduler.Register(() =>
{
int isSuccess = 1;
try
{
var fxConfigServiceUrl = ConfigurationManager.AppSettings["FxConfigServiceUrl"];
if (string.IsNullOrEmpty(fxConfigServiceUrl))
{
//MetricManagerFactory.MetricManager.Set(new ExceptionCountMetric() { HappenedWhere = ExceptionType.OnMetadataSync.ToString() });
return;
}
CmessagingAdminUrl = CentralConfig.GetValue(Consts.Producer_Config_AdminUrl);
ProducerTraceItems.Instance.ProducerConfigUrl = CmessagingAdminUrl;
var timeOutStr = CentralConfig.GetValue(Consts.Producer_Config_Timeout);
if(string.IsNullOrEmpty(timeOutStr))
{
Timeout = Consts.Producer_DefaultTimeout;
}
else
{
int time;
int.TryParse(timeOutStr, out time);
Timeout = time;
}
var connectionMaxCountStr = CentralConfig.GetValue(Consts.Producer_Config_ConnectionMaxCount);
if (string.IsNullOrEmpty(connectionMaxCountStr))
{
ConnectionMaxCount = Consts.Producer_ConnectionMaxCount;
}
else
{
int maxCount;
int.TryParse(connectionMaxCountStr, out maxCount);
ConnectionMaxCount = maxCount;
}
var connectionCountStr = CentralConfig.GetValue(Consts.Producer_Config_ConnectionCount);
if (string.IsNullOrEmpty(connectionCountStr))
{
connectionCount = -1;
}
else
{
int count;
int.TryParse(connectionCountStr, out count);
ConnectionCount = count;
}
}
catch (Exception ex)
{
isSuccess = 0;
Logg.Write(ex, LogLevel.Error, "cmessaging.producer.configutil.runscheduler");
}
finally
{
MetricManagerFactory.MetricManager.Set(new SyncCountMetric { Type = "metadata",IsSuccess = isSuccess.ToString()});
}
}, "ConfigScheduler", 60 * 1000, true);
}