0

I'm using Fiorano's C# support for JMS to publish messages on a topic. Everything goes fine until the application exits. Then it doesn't actually exit. I'm assuming that Fiorano is running a foreground thread (but that's a guess on my part.)

Here's a minimal, but complete, example that illustrates the problem:

    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Linq;
    using fiorano.csharp.naming;
       // Note: Reference to 
       //   Assembly: fmq-csharp-native 
       //   Version: v2.0.50727
       //   Runtime Version: 10.2.0.10533

    namespace NotificationClientTest
    {
        /// <summary>
        /// Main program
        /// </summary>
        public static class Program
        {
            /// <summary>
            /// Main method
            /// </summary>
            /// <param name="args">The arguments.  If any exist we hang.</param>
            public static void Main(string[] args)
            {
                Report("Enter Main"); 
                TheFioranoHangOnExit(args.Any());
                Report("Leave Main");
            }

            /// <summary>
            /// Trigger the problem.
            /// </summary>
            /// <param name="problem"> If true, trigger the problem  </param>
            private static void TheFioranoHangOnExit(bool problem)
            {
                // Initialize queue
                var contextProperties = new Hashtable
                    {
                        { FioranoContext.SECURITY_PRINCIPAL, "user" },
                        { FioranoContext.SECURITY_CREDENTIALS, "secretPassword" },
                        { FioranoContext.PROVIDER_URL, "http://192.168.5.1:1956" },
                        { FioranoContext.BACKUP_URLS, "http://192.168.5.2:1956" },
                        { FioranoContext.INITIAL_CONTEXT_FACTORY, "fiorano.jms.runtime.naming.FioranoInitialContextFactory" },
                    };

                var namingContext = new FioranoNamingContext(contextProperties);
                var topicFactory = namingContext.lookupTCF("PRIMARYTCF");

                if (problem)
                {
                    Report("Creating a connection");
                    var connection = topicFactory.createTopicConnection();
                    connection.stop(); // I've tried swapping the order of stop and close just in case...
                    connection.close();
                }
                else
                {
                    Report("No Connection");
                }
                namingContext.close();
            }

            /// <summary>
            /// Write to console, write to debug window
            /// </summary>
            /// <param name="message">What to say</param>
            private static void Report(string message)
            {
                Console.WriteLine(message);
                Debug.WriteLine(message);
            }
        }
    }

Running this application

    C:\Playground\FioranoHangTest\bin\Debug>NotificationClientTest.exe
    Enter Main
    No Connection
    Leave Main

    C:\Playground\FioranoHangTest\bin\Debug>NotificationClientTest.exe oops
    Enter Main
    Creating a connection
    Leave Main
    [At this point the program hangs.
     ^C or Task Manager can kill it.]

This question describes a similar problem encountered in Java with GlassFish's JMS. Does Fiorano/C# have the same problem?

Otherwise, what am I missing?

Community
  • 1
  • 1
Dale Wilson
  • 9,166
  • 3
  • 34
  • 52

1 Answers1

0

I found an ugly work-around:

        public static void Main(string[] args)
        {
            Report("Enter Main"); 
            TheFioranoHangOnExit(args.Any());
            Report("Leave Main");
            // Evict Fiorano Foreground threads.
            Environment.Exit(0); 
        }

Excuse me, I have to go wash my fingers off with lye soap after typing that one.

I'm still hoping for a better answer.

Dale Wilson
  • 9,166
  • 3
  • 34
  • 52