- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 WebJob 功能...
public class Functions
{
[NoAutomaticTrigger]
public static void Emailer(IAppSettings appSettings, TextWriter log, CancellationToken cancellationToken)
{
// Start the emailer, it will stop on dispose
using (IEmailerEndpoint emailService = new EmailerEndpoint(appSettings))
{
// Check for a cancellation request every 3 seconds
while (!cancellationToken.IsCancellationRequested)
{
Thread.Sleep(3000);
}
log.WriteLine("Emailer: Canceled at " + DateTime.UtcNow);
}
}
}
我一直在研究如何实例化它,我可以通过简单的调用来完成......
host.Call(typeof(Functions).GetMethod("MyMethod"), new { appSettings = settings })
但是,这让我想知道 TextWriter 和 CancellationToken 是如何包含在实例化中的。我发现 JobHostingConfiguration 有 AddService 的方法,并且我尝试使用它注入(inject)我的 appSettings,但它失败并出现错误“异常绑定(bind)参数”。
那么 CancellationToken 如何包含在实例化中以及 JobHostingConfiguration AddService 的用途是什么?
最佳答案
how does CancellationToken get included in the instantiation
您可以使用WebJobsShutdownWatcher 类,因为它有一个 Register 函数,该函数在取消 token 被取消时(即 Web 作业停止时)被调用。
static void Main()
{
var cancellationToken = new WebJobsShutdownWatcher().Token;
cancellationToken.Register(() =>
{
Console.Out.WriteLine("Do whatever you want before the webjob is stopped...");
});
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
what is JobHostingConfiguration AddService used for?
<强> Add Services :通过调用 AddService<> 覆盖默认服务。要覆盖的常见服务是 ITypeLocator 和 IJobActivator。
这是一个自定义IJobActivator允许你使用DI,你可以引用它来支持实例方法。
关于azure - Azure WebJobs 的 JobHostingConfiguration 的 AddService 的用途是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49535406/
来自 MSDN 的关于制作自定义配置部分的示例应该如下所示, class RemoteServiceSection : ConfigurationSection { [Configuratio
我在 iOS CoreBluetooth 上遇到崩溃问题 [CBPeripheralManager 添加服务:]。 似乎是由于 addService 方法中的断言失败而发生的。试了很多方法,还是解决不
我已经创建了系统应用程序。它有一个 aidl 文件和服务。我已经在服务方法 onStartCommand() 中实现了 aidl 接口(interface)和 addService。 mBinder
是否可以使用 C++ Binder API 在两个非特权进程之间进行通信? 我找到的所有示例(例如 https://github.com/mcr/Android-HelloWorldService)都
我创建了一个蓝牙外设管理器。我正在使用 [self.peripheralManager addService:myService] 向这个外设管理器添加一些服务。 对于 iOS7.0,我收到了此方法的
我在我的 angularjs 应用程序中使用了 adsesne 代码。在第一次加载应用程序时,当我动态切换内容时,广告工作正常,出现此错误。 Exception in queued GPT comma
我有以下 WebJob 功能... public class Functions { [NoAutomaticTrigger] public static void Emailer(I
我正在尝试向服务器发送一个 http 帖子,但我从我的 Controller 收到一个格式错误的 url 异常 Controller 代码 public static final String RES
我是一名优秀的程序员,十分优秀!