当我可以让父任务等待它创建的所有任务时,我不确定创建子任务有什么好处.我运行以下代码,它在两种情况下产生相同的结果.
public static void Main(string[] args)
{
RunWithChildren();
RunWithWait();
}
private static void RunWithChildren()
{
Task<Int32[]> parent = Task.Run(() =>
{
var results = new Int32[3];
new Task(r => results[0] = 0, TaskContinuationOptions.AttachedToParent).Start();
new Task(r => results[1] = 1, TaskContinuationOptions.AttachedToParent).Start();
new Task(r => results[2] = 2, TaskContinuationOptions.AttachedToParent).Start();
return results;
});
var finalTask = parent.ContinueWith(parentTask =>
{
foreach (int i in parentTask.Result)
Console.WriteLine(i);
});
finalTask.Wait();
}
private static void RunWithWait()
{
Task<Int32[]> parent = Task.Run(() =>
{
var results = new …Run Code Online (Sandbox Code Playgroud) 我需要编写一个 PowerShell 脚本 shell 来将条目记录到 App Insights 中。我发现这篇文章很有用,但我很难写到除了那里使用的领域之外的不同领域。例如,我正在尝试填充消息字段。我不知道 JSON 中的字段名称,也不知道它应该去哪里。正如你在这个例子中看到的,我尝试将它放置在任何地方,但仍然不起作用。我尝试搜索他们的 REST API 文档,但仍然找不到 JSON 的规范。有人可以帮忙吗?
[{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2018-09-20T16:57:16.1771869Z",
"iKey": "1234",
"message": "This is a message",
"tags": {
"ai.operation.name": "Name",
"ai.user.id": "userId",
"ai.cloud.roleInstance": "Machine 1"
},
"data": {
"baseType": "EventData",
"message": "message1",
"baseData": {
"name": "Event from my service",
"message": "message2",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}]
Run Code Online (Sandbox Code Playgroud)