473,225 Members | 1,310 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,225 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 2252
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.