By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

thread won't start

P: n/a
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.adOpenStreamUnspecifie d,
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();
}
}
}
}
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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/ASPNET...omponents.aspx

http://www.hanselman.com/blog/Catego...Web%20Services

@ Page
======
http://msdn.microsoft.com/library/de.../cpconPage.asp

COM Component Compatibility
===================
http://msdn.microsoft.com/library/de...patibility.asp

COM Interoperability
=============
http://samples.gotdotnet.com/quickst...ominterop.aspx

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

bye
Venkat_KL

Nov 19 '05 #2

P: n/a
One more good article

Calling a COM object from a Web service in .NET

http://www.builderau.com.au/architec...9131286,00.htm

bye
venkat_kl
Nov 19 '05 #3

P: n/a
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
Nov 19 '05 #4

P: n/a
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.
Nov 19 '05 #5

P: n/a
Turns out a referenced dll was not present. Unfortunate that the thread
gave no clue.
Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.