I have a thread pool that calls a sybase function and getting this
message
The current thread used to have an apartment state of MTA,
but the application has CoUnitialized this thread and it is now STA.
This may cause calls on RuntimeCallableWrappers representing some
COM components to fail and may also cause COM component
that are not multi-threaded to be accessed from multiple threads
at the same time which can cause corruption or data loss.
these are the parts
//add work to thread
WaitCallback callback = delegate (object state)
{ threadedPoolInsFunction ((string)state); };
ThreadPool.QueueUserWorkItem(callback, insSqlcmd);
private static void threadedPoolInsFunction(string sybaseCmd)
{
//insert into sybase and capturing threadpool exception
try
{
AseHelper.ExecuteNonQueryCmd(sybasePtsConnString,
sybaseCmd);
}
catch (Exception eT)
{
...
}
}
//utilities
public static void ExecuteNonQueryCmd(string connectionString,string
cmdText)
{
if( connectionString == null || connectionString.Length == 0 ) throw
new ArgumentNullException( "connectionString" );
if( cmdText == null || cmdText.Length == 0 ) throw new
ArgumentNullException( "bad cmdText");
using (AseConnection connection = new
AseConnection(connectionString))
{
connection.Open();
ExecuteNonQueryCmd(connection,cmdText);
connection.Close();
}
}
Throws the thread exception on connection.Close();
Any ideas?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***