473,770 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Enterpri seServices
Imports System.Threadin g

Public Class Calculate
Inherits ServicedCompone nt
Public Sub New()
Dim newThread As Thread = New Thread(AddressO f ThreadMethod)

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

Thread.Sleep(30 0)
' m_count =
System.Threadin g.Interlocked.I ncrement(s_coun t)
If System.Threadin g.Thread.Curren tThread.Apartme ntState <>
System.Threadin g.ApartmentStat e.STA Then
Throw New Exception("Comp onent is not in STA Mode")
Exit Sub
End If

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

End Sub
Private Sub threadMethod()
Thread.Sleep(10 0)
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 1014

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

Similar topics

0
3420
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 think. Point 3 might relate to a threading issue: 1. I have written a C# Winform application that uses Windows messenger automation. When I attempt to send a file through the window messenger object, there is some horrid screen flicking...
6
1256
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; // Serial Communications Thread
7
318
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, Anthony Nystrom
6
1293
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 entries in my temprary file. But when i called abort on thread it is not aborting that thread. After calling aborting still entries are getting inserted into temporary files. That means still recursive function is getting executed. Can some one...
3
1146
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 option, then initiate another menu option, so that both are running at the same time, independently. As each one finished, that thread would end and the main menu would remain. Right now my code is like this: while(true){...
3
1240
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 file (and maybe in the future add more functions) Since I will need to perform two (or more) separate actions on the file (depending on what it is), what would be the best design scenario? Should I implement a Producer/Consumer Queue, or some...
0
907
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 seconds.How can i set one thread to process the screen scraping another thread checking the database . if any cancel request is there , then the processing thread shoudl be stopped . How can i achieve this in one windows service. One thread will...
0
785
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 seconds.How can i set one thread to process the screen scraping another thread checking the database . if any cancel request is there , then the processing thread shoudl be stopped . How can i achieve this in one windows service. One thread will...
5
2268
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 SetCursorCallBack(Cursor cursor); // - Checks to see if the current thread is the creator of the current Form. If the form was // created on another thread, call Invoke so the delegate is ran in the creating thread.
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.