Private Sub EndReading(ByVal ar As IAsyncResult) Dim monParametreAStocker As Object Dim th As New Thread(AddressOf AccessClipBoard) th.SetApartmentState(ApartmentState.STA) th.Start(monParametreAStocker) th.Join() End Sub Private Sub AccessClipBoard(ByVal obj As Object) Clipboard.SetDataObject(obj) End Sub
<MTAThread> _ Shared Sub Main() End Sub
<STAThread> _ Shared Sub Main() End Sub
Dim newThread As Thread = New Thread(AddressOf ThreadMethod) newThread.SetApartmentState(ApartmentState.MTA)
Dim newThread As Thread = New Thread(AddressOf ThreadMethod) newThread.SetApartmentState(ApartmentState.STA)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub MySUB() 'Commence l'operation async de lecture Stream.BeginRead(Buffer, offset, Size, New AsyncCallback(AddressOf EndReading), Nothing) End Sub Sub EndReading(ByVal ar As IAsyncResult) 'on termine l'operation... Stream.EndRead(ar) 'la, notre thread doit etre STA, mais il est MTA... End Sub
Private Sub StartRead() Dim newThread As Thread = New Thread(AddressOf ThreadMethod) newThread.SetApartmentState(ApartmentState.STA) newThread.Start() End Sub Private Sub ThreadMethod() Stream.BeginRead(Buffer, offset, Size, New AsyncCallback(AddressOf EndReading), Nothing) End Sub
MsgBox(Thread.CurrentThread.GetApartmentState().ToString)