DevExpress XtraReport 在后台 运行 即使选项卡已关闭

DevExpress XtraReport is running in background even though tab is closed

我创建了一个包含 5 个子报表的 XtraReport。

这份报告相当大,有 10000 页。在生成报告时,如果我关闭浏览器的选项卡,报告仍在后台生成,而如果我单击进度条的取消按钮,报告生成过程将被放弃。

我的问题是如何在关闭浏览器选项卡时停止生成报告?

我在他们的在线演示中看到了它是如何工作的。简而言之,您可以在卸载、聚焦、模糊之前的 window 事件上执行此操作。 代码来自 demos.devexpress.com/MVCxReportDemos:

(function() {
    var doWithViewer = function(func) {
        var viewer = window['webDocumentViewer'];
        viewer && func(viewer);
    };
    var stopTimeout;
    window.addEventListener("focus", function() { stopTimeout && clearTimeout(stopTimeout); });
    window.addEventListener("blur", function() {
        stopTimeout && clearTimeout(stopTimeout);
        stopTimeout = setTimeout(function() {
            doWithViewer(function(viewer) {
                var reportPreview = viewer.GetReportPreview();
                reportPreview && reportPreview.documentBuilding() && reportPreview.stopBuild();
            });
        }, 3000);
    });
    window.addEventListener("beforeunload", function() {
        doWithViewer(function(viewer) {
            setTimeout(function() { viewer.Close(); }, 1);
        });
    });
})()