473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Running animation in background worker

Pakmarshal
Hi,

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 '<Control ID>' cannot be instantiated because the current thread is not in a single-threaded apartment."

On search i found a link : http://stackoverflow.com/questions/1...418471#1418471

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.
Sep 21 '10 #1
1 2292
The example code is used when you are creating a thread. You are using the background worker so this is a thread pool thread not explicitly created by you.

There is an attribute on the main method that defines if the main thread is sta or mta. This is a parameter is passed into CoInitializeEx which the CLR calls to initialize COM. This will not affect the thread pool thread though. I do not think you can change this for a thread pool thread.

I have never used the video player control you are using but it probably has a dependency on the thread with the main message loop. Windows application has a thing called the message loop that processes messages from the OS. This loop is started via Application.Run or can be flushed by calling Application.DoEvents. Controls, forms, etc can not be access by any other threads besides the one they were created on. To update UI from other threads there is a property called IsInvokeRequired and a method called Invoke on the Control class. IsInvokeRequired tells you if the current thread is not the thread that owns the UI and Invoke is used to invoke a delegate on the UI thread.

It seems like from the error message you are creating this control from the BackgroundWorker.DoWork method. The DoWork method is executed on the thread pool thread and is unsafe to update UI from here unless you use Invoke and IsInvokeRequired. The ProgessChangedEvent and CompletedEvent call Control.Invoke when they are raised so they are safe. If you can create this control here instead of DoWork. If possible pre layout the control on the form and just call Play or whatever method you need.
Sep 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: bryanjhogan | last post by:
Hi all, I have a GUI application that uses timers -------------------- TimerCallback readDelegate; TimerCallback deleteDelegate; private Timer readTimer; private Timer deleteTimer;
1
by: bilosta | last post by:
I need help with background worker and form I have a class (form1) that works with database. I need this: -Show form2 while form1 is geting data from database -When form1 is done, close form2,...
1
by: Flack | last post by:
Hey guys, I'm trying to update a progress bar for a long running process that updates quite frequently. I also would like the GUI to remain responsive to resizing/moving/repainting, etc. ...
6
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
4
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in...
4
by: csharpula csharp | last post by:
Hello, Can you please tell me if I should use the background worker in the following way: if (worker.IsBusy) worker.CancelAsync(); (or I can avoid this if)? And in case I want to restart the...
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
2
by: thoffman | last post by:
Hello again everyone! I have an issue that I can't seem to find a straight answer for anywhere... I have a For loop that sends a file name to a background worker that contains some long running...
1
by: Infog | last post by:
I am trying to code a simple background workers class without needing to use the backgroundworker object on a form. This would allow me to use a background worker in any class without writing much...
0
by: malique84 | last post by:
I am having troubles with a background worker that will have processes running. If the last process started on the background worker completes it calls the RunWorkCompleted method, even if all of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.