在后台工作者中运行动画

发布于 2024-09-24 04:17:02 字数 425 浏览 1 评论 0原文

我正在 vb 2008 中开发一个应用程序,并使用后台工作者来复制文件。我有自己设计的表单,它在表单顶部播放动画以及副本。对于使用“AxMSComCtl2.AxAnimation”播放动画,在执行时我得到

“ActiveX control ''无法实例化,因为当前线程不在单线程单元中。”

在搜索中我找到了一个链接:论坛链接

但是仍在这个链接中首先我不明白在哪里插入这个片段,其次如何在后台工作人员上实现这个想法。

请在这方面指导我。

谢谢&问候,

特立独行者。

I m developing an application in vb 2008, and using background worker to copy file(s). I have my own designed form which plays an animationon on the top of the form along with copy. For playing animation i m using "AxMSComCtl2.AxAnimation", on execution i get

"ActiveX control '' cannot be instantiated because the current thread is not in a single-threaded apartment."

On search i found a link :Forum Link

But still in this link Firstly i dont understand where to insert this snippet and secondly how to implement the idea on background worker.

Please guide me in this regard.

Thanks & Regards,

Maverick.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸠书 2024-10-01 04:17:02

您不能使用BackgroundWorker 来为该控件设置动画。它是一个 ActiveX 控件,需要您在应用程序的主线程中创建它。创建表单的同一线程。

一般来说,这是控件的一个非常常见的限制,它们不支持线程。

链接的线程无法解决您的问题。是的,您可以通过调用 SetApartmentState() 并指定 STA 创建自己的 STA 线程,但现在您无法对在主线程上创建的 Form 执行任何操作。当您将控件添加到表单时,您会遇到异常。窗体的子控件必须在与窗体相同的线程中创建。

一般来说,这应该不是问题。只要保持表单的事件处理程序简短明快,动画就应该相当流畅。如果此类事件处理程序需要执行一些需要一段时间的操作(并因此冻结动画),则让 BGW 执行该工作。

You cannot use a BackgroundWorker to animate this control. It is an ActiveX control, it requires that you create it in your app's main thread. The same thread that creates the form.

This is a very common restriction for controls in general, they do not support threading.

The linked thread does not solve your problem. Yes, you can create your own STA thread by calling SetApartmentState() and specifying STA but now you cannot do anything with the Form that you created on the main thread. You'll get an exception when you add the control to the form. The child controls of a form must be created in the same thread as the form.

This should in general not be an issue. The animation ought to be reasonably smooth as long as you keep the form's event handlers short and snappy. If such an event handler needs to do something that takes a while (and freezes the animation as a result) then let a BGW perform that job.

瀟灑尐姊 2024-10-01 04:17:02

您需要使用委托并让主线程实际控制动画。您从后台线程调用委托,但它在主线程中运行。这个页面,第二篇文章,有一个粗略的想法:
http://www.vbforums.com/showthread.php?t=377205

You need to use a delegate and have the main thread actually control the animation. You invoke the delegate from the background thread but it runs in the main thread. This page, second post, has the rough idea:
http://www.vbforums.com/showthread.php?t=377205

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文