Author |
Message
|
Asim |
Posted: Mon May 17, 2004 1:39 pm Post subject: error 2018 with multiple threads in C# |
|
|
Newbie
Joined: 17 May 2004 Posts: 3
|
Hi,
I am connecting to an MQServer using a C# app. The problem is when I start a new thread, I get error 2018. Creating and running my object in the main thread is no problem.
This works:
SendToMQServer s = new SendToMQServer();
s.SendMsg ();
But this doesn't:
SendToMQServer s = new SendToMQServer();
Thread thSt3 = new Thread(new ThreadStart(s.SendMsg));
thSt3.Start ();
Error occurs in the mqQMgr.AccessQueue method.
I will appreciate it if someone can point me in the right direction. I basically want to start separate threads from the same app to read from database into a queue object, send the messages to the MQServer and get the response back asynchronously.
Thanks in advance. |
|
Back to top |
|
 |
RogerLacroix |
Posted: Mon May 17, 2004 2:27 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
Don't share connection handles between threads!! (Unless you are going to be doing connection pooling.) Open the connection to the queue manager within the thread.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
JasonE |
Posted: Tue May 18, 2004 1:26 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
Hi Roger, Just an FYI but the only slightly interesting thing about this is if the app really is in c# and calls the .NET interface, then handle_share_block is automatically added onto the hconn, except when under a COM+ environment (when you get the same functionality from the mts layer) enabling it to be shared across threads.
I would therefore summaze this isnt using the .net interface or something else is also going on... |
|
Back to top |
|
 |
Asim |
Posted: Tue May 18, 2004 5:39 am Post subject: |
|
|
Newbie
Joined: 17 May 2004 Posts: 3
|
I am opening the connection in the object.
This creates the connection to the queue manager:
SendToMQServer s = new SendToMQServer();
and then this is called:
Thread thSt3 = new Thread(new ThreadStart(s.SendMsg));
thSt3.Start ();
does that mean it isn't part of the thread?
Also I am using IBM.WMQ;
this is the connection string:
mqQMgr = new MQQueueManager(mqQMgrName, channelName, connectionName );
message connection:
requestQueue = mqQMgr.AccessQueue(requestQueueName,MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQCNO_HANDLE_SHARE_NONE );
I have tried with and without: MQC.MQCNO_HANDLE_SHARE_NONE
Is there something else I could do.
Thanks in advance. |
|
Back to top |
|
 |
JasonE |
Posted: Tue May 18, 2004 6:54 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
Can you post a whole, small test pgm which fails for you? |
|
Back to top |
|
 |
JasonE |
Posted: Tue May 18, 2004 6:56 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
Quote: |
requestQueue = mqQMgr.AccessQueue(requestQueueName,MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQCNO_HANDLE_SHARE_NONE ); |
er...
MQCNO* are connection options
MQOO* are are open options
I dont think you want to be providing connection options to the accessqueue call (which is an MQOPEN effectively) |
|
Back to top |
|
 |
Asim |
Posted: Tue May 18, 2004 8:20 am Post subject: |
|
|
Newbie
Joined: 17 May 2004 Posts: 3
|
I figured it out based on your replies.
I was initializing the object instance (which had the connection to the queue manager), then calling the method that sent the messages in a new thread.
That failed because the connection was still being created in the main thread.
Now I create the connection to the queue manager in the actual sendMsg method used to send messages in a loop, so its part of the new thread.
No problems with multiple threads.
Asim. |
|
Back to top |
|
 |
|