Message: the error handling method of ActiveX control cannot be instantiated because the current thread is not in a single thread unit.
Source: Internet
Author: User
Recently, I was working on a simple Screen Saver. The function was very simple, that is, to start a screen saver at a certain interval when the machine was not used for a long time. I want to play some media files (. Avi,. wmv) and Flash files. Therefore, I use Windows mediaplayer as the player.
For some special reasons, I need to start the screen saver in a program without a GUI, so the system. threading. timer is used as the timer, but it is found that the following exceptions are always present during the test:
Message: because the current thread is not in a single thread unit, the ActiveX Control "6bf52a52-394a-11d3-b153-00c04f79faa6" cannot be instantiated ".
Source: system. Windows. Forms
At system. Windows. Forms. axhost .. ctor (string CLSID, int32 flags)
At system. Windows. Forms. axhost .. ctor (string CLSID)
At axwmplib. axwindowsmediaplayer .. ctor ()
...
After a long time, I found that the original windowsmediaplayer control can only be run in a single-threaded environment. Later I changed my timer to system. windows. forms. timer object, and then test. Everything is OK! Conclusion: I found that I did not read the development documents of Ms well when I was writing some programs through this error. I did not pay attention to thread security. I should pay special attention to this issue during the next development.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.