axWindowsMediaPlayer Exception ?

When I create an instance of my page like this :FXrealdetay formdetay =newFXrealdetay(); Exception throws like below :

ActiveX control '6bf52a52-394a-11d3-b153-00c04f79faa6' cannot be instantiated because the current thread is not in a single-threaded apartment.

Error line :this.axWindowsMediaPlayer1 =new AxWMPLib.AxWindowsMediaPlayer();

But from another form when ? create instance and show the page error doesnt throw.it works.

What can I Do?

Thanks.

[1068 byte] By [MetiA] at [2008-1-9]
# 1

On your form, place the STAThread attribute on the static Main function.
This will define the thread that the form is created on as a single-threaded
apartment.

Also, you can set the ApartmentState property of the current Thread to
ApartmentState.STA BEFORE you make any unmanaged calls.

Hope this helps.

Also check this link https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1881289&SiteID=1

KarthikeyaPavanKumar.B at 2007-10-2 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

I set thread1.ApartmentState = ApartmentState.STA; And it works. Thanks.

Karthikeya Pavan Kumar .B wrote:

On your form, place the STAThread attribute on the static Main function.
This will define the thread that the form is created on as a single-threaded
apartment.

Also, you can set the ApartmentState property of the current Thread to
ApartmentState.STA BEFORE you make any unmanaged calls.

Hope this helps.

Also check this link https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1881289&SiteID=1

MetiA at 2007-10-2 > top of Msdn Tech,Windows Forms,Windows Forms General...