c# - “侦听器”上的事件不在 asp.net 中触发,但在控制台应用程序 c# 中有效
问题描述
我已经在控制台应用程序中实现了“Apache Geode”并成功赢得了表格。
我已将此解决方案转换为“类库”。
当我调用这个类库来设置“缓存侦听器”时,它可以在控制台应用程序上运行,但不能在 asp.net (MVC) 应用程序中运行。
我尝试在 Index() 方法中的 MVC HomeController 中调用此 dll。这是dll里面的内容:
internal void RegisterQuoteListener(Cache c, string quoteReqId, Action<string, Quote> AddQuote,
Action<string, QuoteAcknowledgement> AddQuoteAck,
Action<string, QuoteCancel> AddQuoteCancel)
{
List<string> s = new List<string>();
s.Add(quoteReqId);
IRegion<string, Object> q = c.GetRegion<string, Object>("quote");
try
{
q.GetSubscriptionService().RegisterKeys(s);
q.AttributesMutator.SetCacheListener(new LQuote<string, Object>(this, AddQuote, AddQuoteAck, AddQuoteCancel));
}
catch (Exception ex)
{
new ApplicationException("Can't register key: " + quoteReqId, ex);
}
}
public override void AfterCreate(EntryEvent<TKey, TVal> ev)
{
HandleCreateAndUpdate(ev);
}
它的工作方式是为特定键设置一个侦听器,然后当任何具有相同键的消息到达该区域时,它应该触发一个名为“public override void AfterCreate(EntryEvent ev)”的事件
在此示例中是否存在与控制台应用程序不同的 MVC 限制?
我可以根据您的问题提供更多信息。
编辑1
在 MVC HomeController 中,我这样称呼这个助手:
public ActionResult Index()
{
//var a = new Geode().QuoteRequestWrapper("EUR", "GBP", "GBP", DateTime.Now.Date.AddDays(14), 10, "any reference", true);
//Create Instance
Geode geode = new Geode();
//Initialize Cache
geode.InitializeCache(ip, port, pool);
//Send Geode message
geode.GeodePut("region1", Guid.NewGuid().ToString().Substring(0, 8).ToUpper(), "Starting Geode Test");
//Quote request - single
geode.QuoteRequest("EUR", "GBP", "GBP", DateTime.Now.Date.AddDays(14), 10, "any reference", true);
return View();
}
在它里面geode.QuoteRequest
设置了一个“监听器”,它应该从初始化的缓存中触发一个事件到一个方法中。但是永远不会调用该操作。
解决方案
这是答案: 如何使“CacheListenerAdapter”在 ASP.NET 中工作?
如果您使用的 GemFire Native Client 版本低于 10.0.0,那么您可能会在 ASP.NET 中遇到 AppDomain 问题。虽然许多 AppDomain 问题在 9.x 中得到缓解,但有些问题在该版本中无法解决。更新到最新的 10.x 应该可以解决您的问题。
推荐阅读
- ruby-on-rails - 在不同人之间有效分配选项
- django - Django-table2 和 Django-filter 没有过滤
- ios - 如何在一个视图控制器中将数据保存到 CoreData 中,然后让一个表格视图在另一个视图控制器中显示数据?
- python - 如何多次动态调用命令的子命令?
- r - R代码错误地将日期格式写入excel
- laravel - laravel Collection::saveMany 不存在
- google-kubernetes-engine - 在 Google Cloud Stack 驱动程序中创建基于自定义日志的警报
- javascript - 'let' 使用 setTimeout() 进入 for 循环
- python - 通过 ctypes 从 Python 调用 C 代码,使用 python 对象列表
- java - 有没有办法在一个循环中多次更改 JButton 的背景,并有短暂的停顿?