Re: Asynchronous Threading Issue
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 01/19/05
- Next message: Job Lot: "Re: Creating batch process"
- Previous message: lance: "how to set description of window service"
- In reply to: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Next in thread: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Reply: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 19 Jan 2005 21:49:16 -0000
Sam Loveridge <sloveridge@adelaidebank.com.au> wrote:
> Silly me. Should have triple checked the sample code. I didn't call
> method2.BeginInvoke and as a result it doesn't rally highlight the problem
> I'm having at all.
>
> The threading issue I'm trying to work through revolves around the
> System.Net.Sockets.Socket.BeginConnect method. My understanding of async
> callbacks is that if I use a callback function it will execute on a
> different thread to the main thread. However, if I use a callback function
> in the BeginConnect method and note the thread it would appear to be on the
> main thread. This might not be the actual problem, but after that call
> everything in my app goes haywire.
How are you detecting whether or not you're on "the main thread"?
> I want to call BeginConnect so that I try to connect without holding up
> execution on the main thread, but if there's an error connecting I want to
> retry automatically for x number of times. On success I want to then raise a
> public event to notify success. I can get my code to perform the connection
> attempt, and retries and after actually connecting it executes the public
> "Connected" event once (traced to confirm), but when I trace the handler of
> the event I see it has actually executed the number of times I tried to
> connect.
>
> Anyone else seen this? I use a similar form of code to the example I
> attached earlier (which seems to perform correctly after fixing the bug :))
> which leads me to suspect the way BeginConnect operates ???
>
> Suggestions? Examples of using BeginConnect and retries with callbacks
> instead of loops?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that. (I know it'll be similar code to what you posted
before, but it's good to see the updated version.)
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Job Lot: "Re: Creating batch process"
- Previous message: lance: "how to set description of window service"
- In reply to: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Next in thread: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Reply: Sam Loveridge: "Re: Asynchronous Threading Issue"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|