Itcl/Tcom/Tcl/Threads:本帖是否持续运行

Itcl/Tcom/Tcl/Threads: Is this thread continuously running

我在一个线程中编写了 itcl 代码的地方 excel

method Kill_XL {} {
    thread::create {
        set rc [catch {exec taskkill /t /f /im Excel*} output]
    }
    sleep 5
}

之后,对于几个不同的愿望 shell,以下命令调用 Excel 应用程序,但我可以看到它立即退出任务管理器

(shh..) 2 % ::tcom::ref createobject Excel.Application
::tcom::handle0x027CE918
(shh..) 3 % ::tcom::ref createobject Excel.Application
::tcom::handle0x027CE918

上面的内容重复了几个愿望 shell(每个愿望在关闭前一个愿望 shell 后调用)。

在 运行 任何命令上,错误显示为:

"invalid command name ::tcom::handle0x027CE918"

但是下面的代码可以正常打开 Word 应用程序

(shh..) 4 % ::tcom::ref createobject Word.Application
::tcom::handle0x027CE918

等了很久(15-20分钟),重启wish shell 能够运行(没问题)如下代码:

(shh..) 8 % set x [::tcom::ref createobject Excel.Application]
::tcom::handle0x0272EB58
(shh..) 9 % $x Visible 1

并且这次在杀死 excel

后出现了不同的错误消息
(shh..) 10 % thread::create {
                set rc [catch {exec taskkill /t /f /im Excel*} output]
            }
tid00004658


(shh..) 11 % $x Visible 0
0x800706ba {The RPC server is unavailable.}

然后重新开始:

(shh..) 20 %  ::tcom::ref createobject Excel.Application
::tcom::handle0x0272EB58
(shh..) 21 % 
(shh..) 21 % ::tcom::handle0x0272EB58 Visible 1
invalid command name "::tcom::handle0x0272EB58"

线程终止是否导致问题 - 我总是休眠 5 秒以确保终止成功。

还是 tcom-Excel 的其他(已知)问题?

此外,始终给予相同的应用句柄

(shh..) 30 % foreach x  {. .} {puts [::tcom::ref createobject Excel.Application]}
::tcom::handle0x0272EB58
::tcom::handle0x0272EB58

这可能是未发布的 tcom 对象的清理问题 - 它不会在终止关联的 excel 进程时自动清理吗?

这是 OS 的一些问题 - 在 OS 重新成像后不再重复。