0

Playing with Azure WebJobs SDK, when I trigger my function with CallAsync() on JobHost instance, the TextWriter and CancellationToken instances passed into my function get disposed in a second, which makes it useless for logging and monitoring of cancellation state.

For debugging I run my code as console app. The code within Main() looks like:

_host = new JobHost();
_host.StartAsync().Wait();
_host.CallAsync(typeof(Functions).GetMethod("ProcessAggregationsAsync"));

Console.ReadKey();

Here is the function (without logic):

[NoAutomaticTrigger]
public static async void ProcessAggregationsAsync([Table("table1")] CloudTable tbl, TextWriter log, CancellationToken cancelToken)
{
    log.WriteLine("Hello");
    ...
    log.WriteLine("Hello 2"); // --> log is disposed
}

In the function ProcessAggregationsAsync() there is an infinite loop which does some logic (monitoring azure tables and processing some data) and works fine. The problem starts when I add code to check cancellation token or log some characteristics into provided log (TextWriter) they are disposed. Not immediately, it writes 2 entries into log (azure table "azure-webjobs-hosts") but then it fails.

What could be wrong? Why those objects get disposed?

4

1 回答 1

0

糟糕,刚刚注意到函数签名中的明显错误 - 应该有Task而不是void( public static async Task ProcessAggregationsAsync(...))。

多哈。为什么在发布之前我没有看到它?:(

于 2015-09-10T14:36:01.440 回答