473,396 Members | 1,671 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,396 software developers and data experts.

Temporarily switch to STA threading - how???

Hi,

I think I am having some threading issues in a project I am porting from VB6
webclass to VB.NET.
Therefore I would like to temporarily set the threading mode to STA to get
around it until I have
fully ported and tested all code.

I have class that implement IHttpFactory, thus I have a GetHandler method.
However if I try to use the [STAThread] directive, like this:

Public Class MyFactory Implements IHttpHandler

[STAThread] Public Overridable Function GetHandler( ..... )

.... I then get the error that I haven't implemented GetHandler.

If as the first line of my GetHandler implementation I say:

CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA

Then it does not change the threading model used it stays on MTA.

Anybody have any ideas on how I might achieve this?

Regards,
Peter
Nov 20 '05 #1
2 1577
Hi,

It's okay I found another suitable solution.
I used a SyncLock which is adequate for this temporary hack whilst porting.

Regards,
Peter
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Hi,

I think I am having some threading issues in a project I am porting from VB6 webclass to VB.NET.
Therefore I would like to temporarily set the threading mode to STA to get
around it until I have
fully ported and tested all code.

I have class that implement IHttpFactory, thus I have a GetHandler method.
However if I try to use the [STAThread] directive, like this:

Public Class MyFactory Implements IHttpHandler

[STAThread] Public Overridable Function GetHandler( ..... )

... I then get the error that I haven't implemented GetHandler.

If as the first line of my GetHandler implementation I say:

CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA

Then it does not change the threading model used it stays on MTA.

Anybody have any ideas on how I might achieve this?

Regards,
Peter

Nov 20 '05 #2
I was going to say, you really can't switch back and forth from STA to
MTA/free-threading.
Part of the reason is that under the covers the system will at some points
likely call CoInitialize, and you can't initialize COM in the same process
with different threading models.

-Rob Teixeira [MVP]

"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:uF****************@tk2msftngp13.phx.gbl...
Hi,

It's okay I found another suitable solution.
I used a SyncLock which is adequate for this temporary hack whilst porting.
Regards,
Peter
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Hi,

I think I am having some threading issues in a project I am porting from

VB6
webclass to VB.NET.
Therefore I would like to temporarily set the threading mode to STA to get around it until I have
fully ported and tested all code.

I have class that implement IHttpFactory, thus I have a GetHandler method. However if I try to use the [STAThread] directive, like this:

Public Class MyFactory Implements IHttpHandler

[STAThread] Public Overridable Function GetHandler( ..... )

... I then get the error that I haven't implemented GetHandler.

If as the first line of my GetHandler implementation I say:

CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA

Then it does not change the threading model used it stays on MTA.

Anybody have any ideas on how I might achieve this?

Regards,
Peter


Nov 20 '05 #3

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

Similar topics

0
by: Yi-Yu Chou | last post by:
Dear python users, I tried to display 4 vtkRendererWidgets arrayed in a 2x2 grid, and the arrangement would be like : X | Y --| -- Z | T
4
by: Carson | last post by:
Hi, I am now writing a c-code, which is extremely computational extensive. My computer is 2.8GHz Pentium (supports hyperthreading), using cygwin cc (latest version) to compile with the...
2
by: eikel | last post by:
Hi I am a newbie c# programmer, I would like to know how to make a function that switches between languages in windows XP/2000. The languages can be set manually in the language bar. Thanks for...
13
by: William Stacey | last post by:
Using the following code sample: public byte Get() { // <= Possible to switch Here?? lock(syncLock) { //Do something in Get(). } }
2
by: Alison | last post by:
Hi, All, How to temporarily termniate a process and then restart it in VB .Net? (Should not kill the process since it is still needed in the program later). Thanks for the help. Alison
3
by: jojobar | last post by:
Hello, I am trying to localize an existing application (asp.net 2.0). using implicit as well as explicit localization. Asp.net 2.0 uses App_LocalResources folder for implicit localization....
9
by: Tim | last post by:
Hi, I hope this is an easy question for you guys... I have an application that I need to be able to switch from sqlserver to access at runtime. I can change from one sqlserver installation to...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
28
by: Ryan Liu | last post by:
Hi, I have a client/server application, using one thread/client approach. I see very high context switch/sec. What are the ways to reduce it? Each thread sleep longer in its endless loop if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.