Asynchronous program problem. 
Author Message
 Asynchronous program problem.

I have a valid IAccessible object reference in a class.
The Accessible object is obtained from unmanaged code. In
one of the methods of the class I call the BeginInvoke
method of a function delegate. Then, in the AsyncCallback
method, the delegate of which I pass to the BeginInvoke
method, I try to access the Accessible object and call its
methods. The IAccessible method calls do not seem to
return. What could be the possible problem and how could
it be solved?

class A {
        IAccessible accObj;
        AsyncCallback asyncCallback;

        void Method1 (IAccessible obj) {
                accObj = obj;

                // ************  Works    ************
                Object objRole = accObj.get_accRole (0);
                // Print role

                asyncCallback = new AsyncCallback
                                      (Callback);
                Object state = new Object ();
                SomeFuncDelegate.BeginInvoke
                                (asyncCallback, state);
        }

        // AsyncCallback
        void Callback (IAsyncResult ar) {
                // ************ Problem statement *******
                // ************ Why doesn't this return *
                Object objRole = accObj.get_accRole (0);
        }

Quote:
}

Regards,
Saurabh


Wed, 06 Oct 2004 19:56:26 GMT  
 Asynchronous program problem.
Saurabh, in Method1, you might try passing the accObj reference to the
callback routine by passing it in the BeginInvoke call (in which case you
would create a real state object, not just an state object of type Obejct).
Make a state object like this:

public class StateObject
{
    public IAccessible obj;

Quote:
}

In Method1, do this:

StateObject state = new StateObject();
state.obj = accObj;
SomeFunctionDelegate.BeginInvoke(asyncCallback, state);

Now you have set up an object called state that has the reference to accObj
in it. When the callback method is called you would retrieve this reference
like so (1st line of method Callback):

IAccessible accObj = (IAccessible)ar.AsyncState;

Now accObj refers to the object you created in Method1.

-glenn-


Quote:
> I have a valid IAccessible object reference in a class.
> The Accessible object is obtained from unmanaged code. In
> one of the methods of the class I call the BeginInvoke
> method of a function delegate. Then, in the AsyncCallback
> method, the delegate of which I pass to the BeginInvoke
> method, I try to access the Accessible object and call its
> methods. The IAccessible method calls do not seem to
> return. What could be the possible problem and how could
> it be solved?

> class A {
> IAccessible accObj;
> AsyncCallback asyncCallback;

> void Method1 (IAccessible obj) {
> accObj = obj;

> // ************  Works    ************
> Object objRole = accObj.get_accRole (0);
> // Print role

> asyncCallback = new AsyncCallback
>                                       (Callback);
> Object state = new Object ();
> SomeFuncDelegate.BeginInvoke
>                                 (asyncCallback, state);
> }

> // AsyncCallback
> void Callback (IAsyncResult ar) {
> // ************ Problem statement *******
> // ************ Why doesn't this return *
> Object objRole = accObj.get_accRole (0);
> }
> }

> Regards,
> Saurabh



Fri, 08 Oct 2004 22:25:57 GMT  
 Asynchronous program problem.
Glenn I have tried the approach suggested by you. But that
didn't work out.


Sun, 10 Oct 2004 20:06:49 GMT  
 Asynchronous program problem.
Are you sure? That's the approach of the asynchronous design pattern in
.NET. Here's an example:

ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-blockingclientsocketexampl
e.htm
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingnon-blockingclientsocket.
htm

and here's the design pattern itself:

ms-help://MS.VSCC/MS.MSDNQTR.2002JAN.1033/cpguide/html/cpconasynchronousdesi
gnpatternoverview.htm

From your original post I can see that you are not passing the object to the
callback routine so when you try to retrieve the object from the callback
routine it isn't there.

-glenn-


Quote:
> Glenn I have tried the approach suggested by you. But that
> didn't work out.



Sun, 10 Oct 2004 21:39:30 GMT  
 Asynchronous program problem.
Glenn, I have even tried wrapping the IAccessible object
in another class along with some other members. I get the
other members, but, the IAccessible object doesn't work
out.
In my original post I have stored the object as a member
of the class which contains the callback routine. I think
this should have worked.

Quote:
>-----Original Message-----
>Are you sure? That's the approach of the asynchronous
design pattern in
>..NET. Here's an example:

>ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-

blockingclientsocketexampl
Quote:
>e.htm
>ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingnon-

blockingclientsocket.
Quote:
>htm

>and here's the design pattern itself:

>ms-

help://MS.VSCC/MS.MSDNQTR.2002JAN.1033/cpguide/html/cpconas
ynchronousdesi
Quote:
>gnpatternoverview.htm

>From your original post I can see that you are not

passing the object to the
Quote:
>callback routine so when you try to retrieve the object
from the callback
>routine it isn't there.

>-glenn-



>> Glenn I have tried the approach suggested by you. But
that
>> didn't work out.

>.



Mon, 11 Oct 2004 17:00:23 GMT  
 Asynchronous program problem.
Saurabh, it doesn't work like that. Think of your class as a container for
the callback routine and nothing else. In fact, think of the callback
routine as being static in terms of what it can access outside of the
routine itself. The callback routine is called "out of the blue" with no
context except for what is passed to it in the parameters. Therefore, you
*must* get the object from the parameter (see the example I posted to see
how to do this) and not from any class members (because they will all be
0/null).

So just store the object in the StateObject, pass the StateObject to the
BeginInvoice method, and then you can retrieve the object in the callback
routine via the parameter to the callback routine.

-glenn-


Quote:
> Glenn, I have even tried wrapping the IAccessible object
> in another class along with some other members. I get the
> other members, but, the IAccessible object doesn't work
> out.
> In my original post I have stored the object as a member
> of the class which contains the callback routine. I think
> this should have worked.

> >-----Original Message-----
> >Are you sure? That's the approach of the asynchronous
> design pattern in
> >..NET. Here's an example:

> >ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-
> blockingclientsocketexampl
> >e.htm
> >ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingnon-
> blockingclientsocket.
> >htm

> >and here's the design pattern itself:

> >ms-
> help://MS.VSCC/MS.MSDNQTR.2002JAN.1033/cpguide/html/cpconas
> ynchronousdesi
> >gnpatternoverview.htm

> >From your original post I can see that you are not
> passing the object to the
> >callback routine so when you try to retrieve the object
> from the callback
> >routine it isn't there.

> >-glenn-



> >> Glenn I have tried the approach suggested by you. But
> that
> >> didn't work out.

> >.



Mon, 11 Oct 2004 21:47:37 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem with Asynchronous Programming

2. Asynchronous programming.

3. How good is .NET's support for Asynchronous programming

4. Asynchronous programming conundrum

5. A question about asynchronous WinSocket programming.

6. Asynchronous Winsock Programming

7. Asynchronous Socket Data Receiving Problem

8. Asynchronous pluggable protocol....problem

9. Asynchronous Socket problem

10. Problem about Asynchronous Client,is there an Expert can help out,thanks a lot

11. Problem with programming in C/ Creating a Robot Chase Program

12. How to reset a pending asynchronous socket

 

 
Powered by phpBB® Forum Software