Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以在单独的线程中记录MS Insights调用吗?_Javascript_C#_.net_.net Core_Azure Application Insights - Fatal编程技术网

Javascript 我可以在单独的线程中记录MS Insights调用吗?

Javascript 我可以在单独的线程中记录MS Insights调用吗?,javascript,c#,.net,.net-core,azure-application-insights,Javascript,C#,.net,.net Core,Azure Application Insights,我有控制台应用程序,我使用Microsoft insights,但发送事件或异常的速度很慢,所以我希望在不同的线程上发送洞察 let worker = new Worker(__dirname + '/insights.js'); worker.on('message', (msg) => { console.log("First value is: ", msg); //in worker let a = 10000000000; while(a &g

我有控制台应用程序,我使用Microsoft insights,但发送事件或异常的速度很慢,所以我希望在不同的线程上发送洞察

let worker = new Worker(__dirname + '/insights.js');
worker.on('message', (msg) => { 
                console.log("First value is: ", msg);

//in worker
let a = 10000000000;
while(a > 1){
    a--;
}
parentPort.postMessage(a);
我尝试使用工作线程,但它对我没有帮助。它们同步工作。 例如,我创建了新的worker并在那里运行循环


我能以某种方式将事件并行发送到insights中,同时继续运行其他代码吗?

我在index.js中更改了代码,现在我使用以下代码:

function sendLog(functionName, obj , commandName = ''){     
    const cp = require('child_process');
    const subprocess = cp.fork( __dirname + '/insights.js', [], {
        detached: true,
        stdio: [ 'ignore', 'ignore', 'ignore', 'ipc' ]
      });
    subprocess.send({function:functionName, obj: obj, commandName: commandName, UUID : uuid, scriptName: roundCommand});
    subprocess.unref();
}
在insights.js i trackEvent中。工作很好,我可以在后台发送日志。 但在我的index.js中执行命令时,我会运行例如App C#console App的命令,在该命令中我再次执行index.js文件创建新进程:

var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    RedirectStandardError = true,
                    FileName = "cmd.exe",
                    Arguments = $"/C {PathToCommand} {command} {arguments}",
                    WindowStyle = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                }
            };

主要过程将释放。。。我现在不知道为什么,我分离所有子进程。。。。也许新进程是如何从C#应用程序执行的,因此子进程不能与父进程分离。。。。我现在不知道

欢迎来到SO!我做了一些小的语法和语法修改,使问题更容易阅读和查找。我希望你能尽快找到答案!您能否发布在worker运行时尝试运行的代码,以及如何使用App Insights SDK发送事件?发送数据不应该对性能产生重大影响,而使用辅助程序将大大增加准确发送遥测数据的复杂性,因此我不推荐使用。子进程有助于。。。但并非完全如此