ASP.NET异步页面处理 [英] ASP.NET Asynchronous page processing

查看:72
本文介绍了ASP.NET异步页面处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究3层体系结构:UI,BL,DAL.
在我的UI中,我有以下用于异步页面处理的代码:

I am working on 3 tier architecture: UI, BL, DAL.
In my UI i have following code for Asynchronous page processing:

AddOnPreRenderCompleteAsync(new BeginEventHandler(objAsync_BL.BeginAsyncWork1), new EndEventHandler(objAsync_BL.EndAsyncWork1));


objAsync_BL.BeginAsyncWork1 objAsync_BL.EndAsyncWork1是BL中的函数,它们调用DAL的函数objAsync_DL.BeginAsyncWork1 objAsync_DL.EndAsyncWork1.

现在,我正在DAL的EndAsyncWork1中收集字符串类型的输出参数,并且我想将此字符串返回给UI.但是问题在于EndAsyncWork1的返回类型为void;下面是这两个函数的定义:


objAsync_BL.BeginAsyncWork1 and objAsync_BL.EndAsyncWork1 are functions in BL and they call the functions objAsync_DL.BeginAsyncWork1 objAsync_DL.EndAsyncWork1 of DAL.

Now i am collecting an output parameter of type string in EndAsyncWork1 of DAL and i want to return this string to UI. But the problem is that EndAsyncWork1 has return type void; below is the definition of both the functions:

public IAsyncResult BeginAsyncWork1(Object sender, EventArgs e, AsyncCallback cb, object state)
      {
        open();
        op = new SqlParameter("@Result", SqlDbType.VarChar, 50);
        op.Direction = ParameterDirection.Output;

        cmd = new SqlCommand("fs_check", con);
        cmd.CommandType = CommandType.StoredProcedure;

        SqlParameter pm1 = new SqlParameter();
        pm1 = new SqlParameter("@email_id", "abcd");

        cmd.Parameters.Add(pm1);
        cmd.Parameters.Add(op);     

        return cmd.BeginExecuteReader(cb, state);
      }


      public void EndAsyncWork1(IAsyncResult asyncResult)
      {
        string _emailIdFS = null;

        cmd.EndExecuteNonQuery(asyncResult);
        _emailIdFS = op.Value.ToString();
        
        return _emailIdFS;
      }


当我将EndAsyncWork1的返回类型更改为字符串时,出现以下错误:(在BL和DAL中均已更改)

错误1"字符串BusinessLayer.Async_BL.EndAsyncWork1(System.IAsyncResult)"具有错误的返回类型

-------------------------------------------------- ----------------------

BeginAsyncWork1也接受以下参数:


When I am changing the return type of EndAsyncWork1 to string, I am getting the following error: (changed in both BL, and DAL)

Error 1 ''string BusinessLayer.Async_BL.EndAsyncWork1(System.IAsyncResult)'' has the wrong return type

------------------------------------------------------------------------

Also BeginAsyncWork1 accepts following parameter:

(Object sender, EventArgs e, AsyncCallback cb, object state)


我想将另一个字符串类型传递给此函数,例如(Object sender, EventArgs e, AsyncCallback cb, object state, string s)

但是它给出了一个错误,即"BeginAsyncWork1的无重载"与委托"System.Web.BeginEventHandler"匹配


I want to pass one more string type to this function like (Object sender, EventArgs e, AsyncCallback cb, object state, string s)

but it is giving error that "No overload for ''BeginAsyncWork1'' matches delegate ''System.Web.BeginEventHandler'' "

推荐答案

您不能只更改现有方法的签名.这就是为什么它具有状态对象的原因.您可以在其中放置任何喜欢的东西,例如结构或类实例.
You can''t just change the signature of an existing method. That''s why it has a state object. You can put anything you like in there, like a struct or class instance.


这篇关于ASP.NET异步页面处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆