473,407 Members | 2,598 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,407 software developers and data experts.

STA Threading Urgent Please

Stu
Hi,

i have some vb dot net code which needs to be a com+ component ie STA
threaded so variables etc are protected.
So ive built the component and set it up with component services
But when i instaniate the component it keeps telling me its no STA apartment
See following code :-

Any ideas please this is very urgent

TIA

Stu


Imports System.Runtime.InteropServices
Imports System.EnterpriseServices
Imports System.Threading

Public Class Calculate
Inherits ServicedComponent
Public Sub New()
Dim newThread As Thread = New Thread(AddressOf ThreadMethod)

Try
newThread.ApartmentState = ApartmentState.STA
newThread.Start()

Thread.Sleep(300)
' m_count =
System.Threading.Interlocked.Increment(s_count)
If System.Threading.Thread.CurrentThread.ApartmentSta te <>
System.Threading.ApartmentState.STA Then
Throw New Exception("Component is not in STA Mode")
Exit Sub
End If

Catch ex As Exception
Throw New Exception(ex.Message)
Exit Sub
End Try

End Sub
Private Sub threadMethod()
Thread.Sleep(100)
End Sub

Protected Overrides Function canBePooled() As Boolean ''c
Return m_canBePooled
End Function

Protected Overrides Sub activate() ''c
m_canBePooled = False
End Sub

Protected Overrides Sub deactivate() ''c
m_canBePooled = True
End Sub
................
..........................
................................
Nov 21 '05 #1
0 989

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: GrantS | last post by:
I need urgent help. Done OK for a newbie getting automation of Windows Messenger into a Winform C# app but have three problems that I urgently need pointers to. Point 1 and 2 are the same issue, I...
6
by: Carlos Lozano | last post by:
Hi, I have the following problem. I created a Properties section: private SerialComm oComm = new SerialComm(); // Wraps a DLL to handle Serial //comms. private Thread PrinterThread = null;...
7
by: Anthony Nystrom | last post by:
What is the correct way to stop a thread? abort? sleep? Will it start up again... Just curious... If the thread is enabling a form, if the form is disposed is the thread as well? Thanks, ...
6
by: trialproduct2004 | last post by:
Hi all I am having problem at a time of handling threading. I am having application containing thread. In thread procedure i ma using recursive function. This recursive function is adding some...
3
by: Richard MSL | last post by:
I have a C# application that works, with a main menu where the user can choose different options that run, and then return to the menu. I want to change it so that the user can starting running an...
3
by: =?Utf-8?B?TWljaGFlbE4=?= | last post by:
I am designing a multi-threaded application which responds to a FileSystemWatcher events. Depending on the file created, I need to either archive the file to a specific directory, or process the...
0
by: melbenmartin | last post by:
I have to write a Windows Service that will check my my database for fresh request to be processed . At the same time user can cancel the request using request ID. This service will run every 10...
0
by: melbenmartin | last post by:
I have to write a Windows Service that will check my my database for fresh request to be processed . At the same time user can cancel the request using request ID. This service will run every 10...
5
by: Mythran | last post by:
I've read some documentation about accessing objects created in other threads and the code below is similar to what I've gathered for what I have to do: private delegate void...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.