我使用Fiorano的C#支持JMS发布有关主题的消息。 一切顺利,直到应用程序退出。然后它实际上并没有退出。 我假设Fiorano正在运行一个前台线程(但这是我的猜测。)
这是一个说明问题的最小但完整的示例:
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描述了使用GlassFish的JMS在Java中遇到的类似问题。 Fiorano / C#有同样的问题吗?
否则,我错过了什么?
答案 0 :(得分:0)
我找到了一个丑陋的解决办法:
public static void Main(string[] args)
{
Report("Enter Main");
TheFioranoHangOnExit(args.Any());
Report("Leave Main");
// Evict Fiorano Foreground threads.
Environment.Exit(0);
}
对不起,打完那个后我必须用碱液把手指洗掉。
我仍然希望得到更好的答案。