1

I'm working with IBM Websphere MQ 7.5.0.5 and I found out under some circumstances, the constructor of a QueueManager hangs when the server side shuts down. This constructor is surrounded by "using" clause like the following code. How can I forcibly terminates the constructor function after a certain time?

using (mqQueueManager = new MQQueueManager(this._queueManager, this._properties))
ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
  • 1
    You may be able to find something in http://stackoverflow.com/questions/4238345/asynchronously-wait-for-taskt-to-complete-with-timeout. – Olaf Keijsers Aug 07 '15 at 21:02

1 Answers1

0

You can do something like this in your function to instantiate MQQueueManager:

       System.Threading.Thread thread = new System.Threading.Thread(()=>{

        using (mqQueueManager = new MQQueueManager(this._queueManager, this._properties))
        {
        }

        });
        thread.Start();
        var isComplete = thread.Join(TimeSpan.FromSeconds(30));

        if (!isComplete)
        {
            thread.Abort();
        }
Deepak Bhatia
  • 1,090
  • 1
  • 8
  • 13
  • But once the thread exits, the mqQueueManager object gets disposed by leaving the using clause and I can't use it in the main thread. So I will need to move all logic into that thread's work? – cantbenewbieforlife Aug 10 '15 at 14:24
  • If you want to keep on using mqQueueManager then why you are disposing it? Just create new instance of mqQueueManager, don;t dispose it, you can then use that instance in your main thread. – Deepak Bhatia Aug 10 '15 at 15:30
  • I was trying to utilize the automatic disposing of "using" clause. But I think this is fine. I can manually dispose later if without the "using" clause. – cantbenewbieforlife Aug 10 '15 at 17:56
  • 1
    Be sure to observe [MQ's threading model](http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q029590_.htm?lang=en) or you may find the app still blocks, just somewhere else. Also, some of that blocking behavior in modern MQ clients is tuned in the client's ini file as reconnect parameters. If reconnect is enabled and has a long timeout set, you might just try reducing it. – T.Rob Aug 12 '15 at 16:47