MTA / STA Forms and Flash

CdRsKuLL

Active member
Joined
Sep 26, 2006
Messages
40
Programming Experience
Beginner
Hi all.. sorry if this is posted in the wrong forum and I have had a search about but cant seem to find a answer..

My problem is I'm using a COM object that needs to have MTA enabled.. so I have this on my form.

VB.NET:
<MTAThread()> _
    Sub Main()
        Dim frm1 As Form1
        ' Instantiate (create) a new Form1 object and assign
        ' it to variable frm1.
        frm1 = New Form1()
        ' Call the Application class' Run method
        ' passing it the Form1 object created above.
        Application.Run(frm1)

    End Sub

The main com object loads and works great but only in MTA, the problem I'm having is now I want to place flash either on the form1 if possible if not on form2.. but I get a message saying that it only will run in STA and not MTA.. So I have looked about and read lots of stuff, half of which I dont understand.. lol but nothing comes to light.

any help please.. I've been coing in vb, and decided to 'cross over' to the otherside.. but things have got tricky already.. lol

Steve
 
Thread.SetApartmentState Method can be used before new thread is started, running thread can't be changed. Here is a simple example, commented out is the msgbox code where you can see current threads apartment state.
VB.NET:
Sub startSTA()
  Dim t2 As New Threading.Thread(AddressOf threaded2)
  t2.SetApartmentState(Threading.ApartmentState.STA)
  t2.Start()
End Sub
Sub threaded2()
  'MsgBox(Threading.Thread.CurrentThread.GetApartmentState.ToString)
  Dim f As New Form1
  f.ShowDialog()
End Sub
 
thanks m8, the only vb.net example I could find was Dim T as Thread which I can only assume was from 2003 not 2005 express like i'm using. I will give it a go and let you know how I get on.

Cheers

Steve
 
Back
Top