我在使用以下代码记录到 Application Insights 时遇到问题:
var configuration = new TelemetryConfiguration();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);
client.TrackEvent($"TEST EVENT", properties: new Dictionary<string, string>() { { $"TEST Property", $"TEST Value".ToString() } });
每当我使用下面的代码时,遥测数据都会毫无问题地记录下来,但是,由于这不是异步调用,我们永远不会得到IsCancellationRequested
asFALSE
并且这会进入无限循环。
CancellationTokenSource tokenSource = new CancellationTokenSource();
CancellationToken token = tokenSource.Token;
var configuration = new TelemetryConfiguration();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);
while (!token.IsCancellationRequested)
{
client.TrackEvent($"TEST EVENT", properties: new Dictionary<string, string>() { { $"TEST Property", $"TEST Value".ToString() } });
}
有人可以帮我确定我是否在这里遗漏了什么吗?
-沙拉布