为什么这个程序需要MsgBox?
长话短说:我正在尝试编写一个应用程序,将 IE 的历史记录转储到文本文件中。因为我很懒,所以我去寻找一个预先存在的库,并找到了这个漂亮的项目来构建: http://www.freevbcode.com/ShowCode.asp?ID=6702。只是,我被困住了......
我终于有了转储历史记录的程序,但是如果我在第 169 行放置 MsgBox() ,它只能工作。 >Module1.vb。我尝试在那里放置一个 Thread.Sleep() ,但这不起作用。那里必须有一个消息框,否则只会列出今天的历史记录。
我的猜测是,由于这是与 wininet.dll
通信,所以这是一个并发问题。 Thread.Sleep()
(对于 For...Next 循环)停止程序监听;在分配值之前,没有什么可以让它退出循环,但 MsgBox() 是正确的。除了MsgBox()之外还有什么东西可以达到同样的效果吗?我希望不必点击“确定”三十次即可使程序正常运行。
这是我的分支/版本/派生工作: http://profnano.org/andy/misc /img/HistList.zip;这是一个VS.NET2003项目。
Long story short: I'm trying to write an app that'll dump IE's history to a text file. Because I am lazy, I went searching for a preexisting library and found this beautiful project to build from: http://www.freevbcode.com/ShowCode.asp?ID=6702. Only, I'm stuck...
I finally got the program to dump the history, but it only works if I put a MsgBox()
on line 169 of Module1.vb. I've tried putting a Thread.Sleep()
there, but that doesn't work. There has to be a message box there, or only today's history gets listed.
My guess, since this is talking to wininet.dll
, is this is a concurrency thing. Thread.Sleep()
(for a For...Next loop) stops the program from listening; nothing there makes it exit the loop before values are assigned, but a MsgBox() is just right. Is there something besides MsgBox() that will have the same effect? I'd like to not have to hit OK thirty times to make the program work.
Here's my branch/version/derived work: http://profnano.org/andy/misc/img/HistList.zip; it's a VS.NET2003 project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MsgBox() 泵送消息循环。这可以让所有类型的代码摆脱困境。窗户有机会自行粉刷。由于主线程陷入循环而导致的 COM 死锁得到解决,这在涉及 IE 时始终是一个问题。调用 DoEvents() 是 MsgBox() 的非常不完美的替代方案。
MsgBox() pumps a message loop. That can get all kind of code unstuck. Windows get a chance to paint themselves. COM deadlocks due the main thread getting stuck in a loop are solved, always an issue when IE is involved. Calling DoEvents() is the very imperfect alternative to MsgBox().