473,410 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Asynchronous events exception handling

I have a remoting object, lets call it A, that fires an event to remotely
registered handlers, lets call it B.
The invocation is working OK and the remote handler B is handling the event
like it should.

But I need A to catch any exception thrown from the handler B, and also I
need that A will get the returned value returned by handler B.
For that I wrote:

private void ResultsHandler(IAsyncResult ar)
{
// Extract the delegate from the AsyncResult.
MyEventHandler handler =
(MyEventHandler)((System.Runtime.Remoting.Messagin g.AsyncResult)ar).AsyncDelegate;

// Obtain the result which I do not have because the delegate is void,
// but still need to that in order to catch exception caused in the.
handler.EndInvoke(ar);
}

public void RemtinMethod(long[] IDs)
{
// I'm using the AsyncCallback and state Object to be able to catch
exception caused in the delegate asynchronous invocation.
AsyncCallback cb = new AsyncCallback(ResultsHandler);
Object state = new Object();

if( RemoveDefectHandler != null )
{
foreach( MyEventHandler handler in MyEventHandler.GetInvocationList() )
{
try
{
handler.BeginInvoke(IDs, cb, state);
}
catch( Exception )
{
throw;
}
}
}
}
But still I can not get the returned value, and I'm also not catching at A
any thrown exception from B.

What I'm I doing wrong?

Is there any difference if I using the VS2003 or the VS2005? If so, what is
it?
--------
Thanks
Sharon
Jan 16 '06 #1
9 2258
Hello again,
I have some more info that may help.

(1) In the code I have posted I don't need the returned value.
(to get the returned value I just need to add: int result =
handler.EndInvoke(ar); at the ResultsHandler() )

(2) I can catch any exception thrown from B at the ResultsHandler(), but the
ResultsHandler() is invoked from another thread and not the invoking thread
(A that invoke the handler.BeginInvoke(IDs, cb, state);),
But I need to catch the exception at the calling thread A.
How do I do that?
---------
Thanks
Sharon
Jan 16 '06 #2
Hello Sharon,

How about catching exception just in B (ResultsHandler), and pass the
exception information back as result?

Luke

Jan 17 '06 #3
Thanks Luke,

That would be great.
But how can I do that? they are in a different thread.
---------
Thanks
Sharon
Jan 17 '06 #4
As you have posted:

to get the returned value I just need to add: int result =
handler.EndInvoke(ar); at the ResultsHandler() )

Luke

Jan 18 '06 #5
That's good. But I need to catch also the exceptions and that also can be
done at the ResultsHandler(). But the ResultsHandler() is invoked from
another thread then the thread the BegineInvoke() was called, and I need this
two values (returned value and caught exception) at the thread that invoked
the BegineInvoke() - calling thread A.

Is there a easy way to do that?
--
Thanks
Sharon
Jan 18 '06 #6
You may return a collection or array intead of a single object as returned
value. This is not perfect solution, but I don't there is a better one to
catch such an exception in another thread.

Luke

Jan 19 '06 #7
But it's impossible to just return, the ResultsHandler() does not return any
value and even if does, where this returned value will go to. As the
ResultsHandler() is in different thread then the thread I need the returned
value and exception.

There must be a comfortable way to do that. What is it?

-------
Thanks
Sharon
Jan 19 '06 #8
Hello Sharon,
But it's impossible to just return, the ResultsHandler() does not
return any value and even if does, where this returned value will go
to. As the ResultsHandler() is in different thread then the thread I
need the returned value and exception.

There must be a comfortable way to do that. What is it?


My preferred approach to communicate exceptions across threads is using events.
Assume you have two classes: class A uses an asynchronous service offered
by class B. B also has an "Error" event, for which A registers an event handler
before invoking any of B services. In all of B's relevant catch blocks, B
fires of its Error event to notify its clients (such as A) of an exception.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 19 '06 #9
Communicating among thread is fine, but I just thought that the asynchronous
delegates like I'm using by Remoting has this mechanism built in to catch
exception and return value in the calling thread and not in a callback at
another thread.

-------
Thanks
Sharon
Jan 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
15
by: Javier Estrada | last post by:
Can someone explaing the difference between these exception models regarding the structured exception handling? The documentation is not clear. Some code would actually help. Thx
3
by: Anders Both | last post by:
Does someone know´s about using threads and/or asynchronous programming inside asp.net (inside the asp.net process). I am here not speaking about the thing that the IIS makes new threads for each...
4
by: taskswap | last post by:
I have a legacy application written in C that I'm trying to convert to C#. It processes a very large amount of data from many clients (actually, upstream servers - this is a mux) simultaneously. ...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
2
by: =?Utf-8?B?S2FseWFu?= | last post by:
Hi, I have to make multiple calls (about 400K) to a webservice which returns a string. And currently it takes about a week to make all the calls. Instead of waiting for the webservice result ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.