?
Solved

IASyncResult: Accessing delegate method attributes

Posted on 2005-04-05
7
Medium Priority
?
420 Views
Last Modified: 2010-05-18
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
Comment
Question by:prosperion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13714096
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
 

Author Comment

by:prosperion
ID: 13715696
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
 
LVL 11

Accepted Solution

by:
jatinderalagh earned 1500 total points
ID: 13715742
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:prosperion
ID: 13731786
The callback function is definitely not being called.
0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13733283
how did you verified that
0
 

Author Comment

by:prosperion
ID: 13743071
Using the debugging function of VS
0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13744255
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question