Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

IASyncResult: Accessing delegate method attributes

public delegate int AsyncReadDelegate(int rowid);

public void readAsyn(int rowid)
{
    AsyncReadDelegate dlgt = new AsyncReadDelegate(read);
    IAsyncResult ar = dlgt.BeginInvoke(rowid, new AsyncCallback(CallbackReadAsyn),dlgt);
}

static void CallbackReadAsyn(IAsyncResult ar)
{
    AsyncReadDelegate dlgt = (AsyncReadDelegate)ar.AsyncState;
    int result = dlgt.EndInvoke(ar);
}

Does anyone know how I can access the rowid attribute in CallbackReadAsyn()?
The delegate represents the read operation which takes in an int, called rowid.
Surely u can access the attributes in the delegate like the original operation?

Thanks
0
prosperion
Asked:
prosperion
  • 4
  • 3
1 Solution
 
jatinderalaghCommented:
Is your code working properly. Cause AsyncState property Gets a user-defined object that qualifies or contains information about an asynchronous operation.


using System.Runtime.Remoting.Messaging;

static void CallbackReadAsyn(IAsyncResult ar)
{

 // Obtains the last parameter of the delegate call.
    int value = Convert.ToInt32(ar.AsyncState);

    // Obtains return value from the delegate call using EndInvoke.
    AsyncResult aResult = (AsyncResult)ar;
    AsyncReadDelegate temp = (AsyncReadDelegate )aResult.AsyncDelegate;
    int result = temp.EndInvoke(ar);
}
0
 
prosperionAuthor Commented:
Ive just found out that my callback method isnt being called at all. I'm running all this on a C# web application. Will it make any diff if i run it as a windows form app? Otherwise, what could be the problem?

It is almost like a carbon copy of the example they give on msdn on IAsycnResult.
0
 
jatinderalaghCommented:
I will suggest not to use asynchronous operation in web form.
Cause if the page is rendered before your callback then you wouldn't get the result as page is already sent to client.

If you still want to check it.
Put a break point in your prerender event of the form.  And then check whether your calllback is working or not.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
prosperionAuthor Commented:
The callback function is definitely not being called.
0
 
jatinderalaghCommented:
how did you verified that
0
 
prosperionAuthor Commented:
Using the debugging function of VS
0
 
jatinderalaghCommented:
Make a synchornous call if you get the result then you don't have any problem with the delegate.
To me it looks like you are having the problem which i already described.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now