ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » error 2018 with multiple threads in C#

Post new topic  Reply to topic
 error 2018 with multiple threads in C# « View previous topic :: View next topic » 
Author Message
Asim
PostPosted: Mon May 17, 2004 1:39 pm    Post subject: error 2018 with multiple threads in C# Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Mon May 17, 2004 2:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
JasonE
PostPosted: Tue May 18, 2004 1:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Asim
PostPosted: Tue May 18, 2004 5:39 am    Post subject: Reply with quote

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
View user's profile Send private message
JasonE
PostPosted: Tue May 18, 2004 6:54 am    Post subject: Reply with quote

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
View user's profile Send private message
JasonE
PostPosted: Tue May 18, 2004 6:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Asim
PostPosted: Tue May 18, 2004 8:20 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » error 2018 with multiple threads in C#
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.