473,385 Members | 1,888 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,385 software developers and data experts.

How to throw exception from asynch socket callback

I am using asynch sockets and so I call BeginReceive and then in my
callback function I have certain events that would cause me to want to
throw an exception.

The problem of course is that the callback function is executing in a
separate thread from the main thread so when I throw the exception
it's apparently impossible to handle it in the calling thread (ie the
thread that called BeginReceive(..).

Is there a way to throw an exception to another thread like this?

Thanks,
Barry
Nov 15 '05 #1
1 3399

"Barry Anderberg" <ba******@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
I am using asynch sockets and so I call BeginReceive and then in my
callback function I have certain events that would cause me to want to
throw an exception.

The problem of course is that the callback function is executing in a
separate thread from the main thread so when I throw the exception
it's apparently impossible to handle it in the calling thread (ie the
thread that called BeginReceive(..).

Is there a way to throw an exception to another thread like this?


If you want to process the the exception in the same thread that called
BeginReceive, then don't use async sockets. Or don't use a callback, and
call EndReceive.

If you are going to use async sockets, you will have to pass enough state to
the callback function for it to be able to handle the exception: you have to
move the appropriate exception handling context over callback thread.
Basically this involves creating a state object to hold what would otherwise
be local variables, and each of your callback functions reads and writes to
data in the state object, and always passes it on to the next callback.

David

This is really what makes async IO hard.

David
Nov 15 '05 #2

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

Similar topics

0
by: Martin B | last post by:
Hallo to everyone! Problem: -------- GridView Exception: reentrant call to the SetCurrentCellAddressCore function System: ------- WinXP Professional, english, .NET Framework 2.0 Beta...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
1
by: Simon M | last post by:
Hi, I'm not sure where to post this as it's about windows forms, web forms, socket communication and embedded objects. I am developing a smart client which is embedded in a webform. This...
0
by: suranasaurabh | last post by:
How to create a synchronous Socket in C#.Net? In VC++ we have AsynchSocket class to do that... but in C# is there anything???? Socket from System.net is not useful since its a blocking...
1
by: Sean | last post by:
I am looking at using delegates to perform an asynchronous call. There will be a callback invoked at the end of the call. The client thread will wait on the WaitHandle from IAsyncResult (which is...
4
by: EM_J | last post by:
I am implementing this interface in one of my pages. The RaiseCallbackEvent method runs a task for about 3 seconds. I've noticed when I am on that page and click a tab to navigate to another...
6
by: David | last post by:
http://msdn2.microsoft.com/en-us/library/bew39x2a(VS.80).aspx I was looking at above link and I just don't see the advantage of this. The main thread is just stopping and waiting for each of the...
6
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include...
2
by: Peter Duniho | last post by:
On Fri, 19 Sep 2008 11:37:30 -0700, TN <ginkeq@yahoo.comwrote: Did you call BeginReceiveFrom()? Or BeginReceive()? If the latter, then that's your problem. You need to call...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.