thread won't start

D

Doug Kent

Hi,

I am using a STA thread to run a COM object.

On a couple of machines the thread runs fine. On another machine the thread
won't start, and no exceptions are thrown.

This code is running in a web service implemented using C#, ASP.NET 1.1, IIS
5.1, Windows 2000 Server.

Any suggestions appreciated! Here is some code. The method
xmlLoader.Load() is never invoked.

To start the thread:

XmlBulkLoader xmlLoader = new XmlBulkLoader();
ThreadStart workThreadDelegate = new ThreadStart(xmlLoader.Load);
Thread workThread = new Thread(workThreadDelegate);
workThread.ApartmentState = ApartmentState.STA;
workThread.Name = "XMLBulkLoader";
workThread.Start();
workThread.Join();

The code that is not running when it should (xmlLoader.Load):

public class XmlBulkLoader
{
public void Load()
{
ADODB.Stream xmlDataStream = null;
try
{
xmlDataStream = new ADODB.StreamClass();
xmlDataStream.Open(System.Type.Missing,
ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
null, null);
xmlDataStream.WriteText(_xmlData, ADODB.StreamWriteEnum.adWriteChar);
xmlDataStream.Position = 0;
SQLXMLBulkLoad3 objBL = new SQLXMLBulkLoad3();
objBL.ConnectionString=_dbConnection;
objBL.ErrorLogFile = Path.Combine(_logFilePath, "sqlbulkloaderror.log");
objBL.CheckConstraints = true;
objBL.Transaction = true;
objBL.XMLFragment = false;
objBL.SchemaGen = false;
objBL.KeepIdentity = false;
objBL.KeepNulls= false;
objBL.IgnoreDuplicateKeys = false;
objBL.ForceTableLock = false;
objBL.SGDropTables = false;
objBL.Execute(_schemaFile, xmlDataStream);
}
catch(Exception ex)
{
exception = ex;
}
finally
{
if (xmlDataStream != null)
{
xmlDataStream.Close();
}
}
}
}
 
G

Guest

Dear Doug Kent

As far as I know,
In ASP.NET, the thread pool is a multithreaded apartment (MTA) by default.
And When which can affect the performance of traditional apartment-threaded
(ie STA - Single Threaded Apartment) Visual Basic 5 and Visual Basic 6
components

If it is a page (ie webpage you could have set the AspCompat Attribute of
the Page Directive to True)

AspCompat
=======
When set to true, this allows the page to be executed on a single-threaded
apartment (STA) thread. This allows the page to call STA components, such as
a component developed with Microsoft Visual Basic 6.0. Setting this attribute
to true also allows the page to call COM+ 1.0 components that require access
to unmanaged Active Server Pages (ASP) built-in objects. These are accessible
through the ObjectContext object or the OnStartPage method. The default is
false.
Note Setting this attribute to true can cause your page's performance to
degrade. For more information, see the Remarks section.

When the AspCompat attribute is set to true for a page, if you use a
constructor to create a COM component before the request is scheduled, it
will run on a multithreaded apartment (MTA) thread. Doing this causes
significant Web server performance degradation. To avoid this problem, create
COM components only from within one of the Page events (such as Page_Load,
Page_Init, and so on) or one of the Page methods. Be sure as well that the
objects are not created at page construction time. The following examples
demonstrate the incorrect and correct way to instantiate a COM object in an
AspCompat page. MyComObject is the component, and comObj is the instance of
the component.

In you case, since it is webservie,

ASP.NET WebServices calling Apartment-Threaded COM Components...

If you've ever had to call a VB6 Component from an ASP.NET (ASMX) XML Web
Service, you may (most probably) get threading errors. In ASP.NET Apps you
can mark the Page directive with "ASPCompat='true'" but there is not a
equivalent tag for Web Services. So, there's a few things you can do:

Put the VB Component in COM+ (Preferred if the COM Object is part of a
larger interaction, and you want fine control over your SOAP)

Figure out a different way to expose the COM Object as a Web Service,
perhaps with Classic ASP and SOAP Toolkit 3.0 (Quick if you just want to get
your component, but has larger design ramifications for big systems)

for futher infor please look into ...,

http://www.hanselman.com/blog/ASPNETWebServicesCallingApartmentThreadedCOMComponents.aspx

http://www.hanselman.com/blog/CategoryView.aspx?category=Web Services

@ Page
======
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconPage.asp

COM Component Compatibility
===================
http://msdn.microsoft.com/library/d...guide/html/cpconCOMComponentCompatibility.asp

COM Interoperability
=============
http://samples.gotdotnet.com/quickstart/aspplus/doc/cominterop.aspx

Developing High-Performance ASP.NET Applications
=================================
http://msdn2.microsoft.com/en-us/library/5dws599a

bye
Venkat_KL
 
D

Doug Kent

Thanks! I would like to know why the code works on some computers and not
others. I note that the computer on which it *doesn't* work is Windows 2000
Server, while the ones on which it *does* work are Windows XP Pro.

-d
 
D

Doug Kent

OK, I found a computer with SQL Server 2000 on which the code *does* work.
So it is not that. There is some other difference.
 
D

Doug Kent

Turns out a referenced dll was not present. Unfortunate that the thread
gave no clue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top