Click here to Skip to main content
16,014,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on 3 tier architecture: UI, BL, DAL.
In my UI i have following code for Asynchronous page processing:
C#
AddOnPreRenderCompleteAsync(new BeginEventHandler(objAsync_BL.BeginAsyncWork1), new EndEventHandler(objAsync_BL.EndAsyncWork1));

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:
C#
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;
      }

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:
C#
(Object sender, EventArgs e, AsyncCallback cb, object state)

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' "
Posted
Updated 30-Jul-10 1:02am
v3
Comments
R. Giskard Reventlov 30-Jul-10 6:47am    
1: Poorly formatted - no one is going to bother wading through this.
2: What's the question (you don't seem to be specifically asking for anything)?
brian004 30-Jul-10 6:53am    
@digital man: It is clearly mentioned that what I am looking for:
"Now i am colleceting an output parameter of type string in EndAsyncWork1 of DAL and i want to return thisstring to UI. But the problem is that EndAsyncWork1 has return type void; below is the defination of both the functions:"

1 solution

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.
 
Share this answer
 
Comments
brian004 30-Jul-10 6:58am    
Hi Christian Graus,
Thanks for ur answer, can u please elaborate in details?. My problem is in "Now i am colleceting 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;"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900