2016-06-17 32 views
0

我正在使用Fiorano的C#支持JMS發佈有關主題的消息。 一切都很好,直到應用程序退出。然後它不會實際退出。 我假設費奧拉諾正在運行的前臺線程使用Fiorano JMS的C#應用​​程序在出口處掛起

這裏有一個最小的,但完整的,例子說明了這個問題(但是這是我的一個猜測。):

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); 
      } 
     } 
    } 

運行此應用程序

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描述了Java在GlassFish的JMS中遇到的類似問題。 Fiorano/C#有同樣的問題嗎?

否則,我錯過了什麼?

回答

0

我發現了一個醜陋的變通辦法:

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

對不起,我得去洗我的十指關,用鹼液肥皂鍵入一個後。

我仍然希望有更好的答案。

相關問題