无法在 ASP.NET MVC 中触发事件

问题描述

我遇到了一个问题,我需要一些帮助。

我想显示来自服务器的实时值(统计数据)。已经有一个 dll 来实现来操作服务器(连接、获取值等)

dll一般是:

public Class ServerClass
{
    // attributes 
    // constructor
    // methods 

    public event EventHandler Received;
}

我在 Windows 窗体上尝试了这段代码,它运行良好。我立即得到值。

using dll_name;

private void BtnGet_Click(object sender,RoutedEventArgs e)
{
    // class instantiation
    ServerClass c = new ServerClass() 

    // with parameters
    // set attributes
    c.Received += OnReceivedResponse;
}

private void OnReceivedResponse(object sender,EventArgs e)
{
     listBox.Items.Add(e.toString());
}

现在我想在 ASP.NET MVC 中做同样的事情,但我无法获取值。

我尝试过的:

// global.asax
public class WebAppli: HttpApplication{
public static ServerClass c;

protected void Application_Start(object sender,EventArgs e)
{
     c = new serverClass() // with params
}

// controller
public void Result()
{ 
    Response.ContentType="text/stream";

    // code

    WebAppli.c.Received += (sender,ev)=>
         {
             // All code inside this function doesn t work
             Response.Write("data:{0}\n\n",ev.toString())
             Response.flush
         }
}

是否应该在 global.asax(asp.net 生命周期)中设置某些内容

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)