473,909 Members | 5,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Runti me.Remoting.Mes saging.AsyncRes ult)ar).AsyncDe legate;

// 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.EndInvo ke(ar);
}

public void RemtinMethod(lo ng[] 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(R esultsHandler);
Object state = new Object();

if( RemoveDefectHan dler != null )
{
foreach( MyEventHandler handler in MyEventHandler. GetInvocationLi st() )
{
try
{
handler.BeginIn voke(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 2278
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.EndInvo ke(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.BeginIn voke(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.EndInvo ke(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********@joer gjooss.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
5445
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
1
2850
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 remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because essentially my worker thread updates the UI, which is BAD. So, here I am trying to figure out how...
4
17282
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 maintain the reference to any module.
15
3282
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
1215
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 request, but about starting a thread inside the asp.net process. I am making big use of this thing in my applikation, but I have the problem that when exceptions/errors uccur no message is bein showed. When VS is running a wery undetaild message...
4
3827
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. I've read through what must be dozens of ways to do socket communication in C#, and it seems they all devolve into three basic options - Socket.Select, IOCP through a native interface, and Asynchronous callbacks. I'm fine using Asynchronous...
1
3051
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 the web service methods. What I like about the asynchronous calls that they use events. So when I call the web service operation is finished is fires the event. So all my objects that I'm using in my client application just subscribe to whatever...
1
1782
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 the web service methods. What I like about the asynchronous calls that they use events. So when I call the web service operation is finished is fires the event. So all my objects that I'm using in my client application just subscribe to whatever...
2
1628
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 before i make the next call, I rather want to make the calls and let the results comeback at its own pace. I used Asynchronous calling and callback method, but it does not seems to work. I am sure, asynchronous way will improve my program execution...
0
10037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9879
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11052
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10540
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7249
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5938
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.