Re: Asynchronous Threading Issue
From: Sam Loveridge (sloveridge_at_adelaidebank.com.au)
Date: 01/19/05
- Next message: lance: "how to set description of window service"
- Previous message: jthoward_at_voicenet.com: "Migration - XLA to .NET"
- In reply to: Kevin Yu [MSFT]: "RE: Asynchronous Threading Issue"
- Next in thread: Jon Skeet [C# MVP]: "Re: Asynchronous Threading Issue"
- Reply: Jon Skeet [C# MVP]: "Re: Asynchronous Threading Issue"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 Jan 2005 08:01:31 +1030
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.
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?
Sam.
"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:3w5HlWg$EHA.2504@cpmsftngxa10.phx.gbl...
> Hi Sam,
>
> First of all, I would like to confirm my understanding of your issue. From
> your description, I understand that there is something wrong with the
> multi-thread app, in which Test2 never get called. If there is any
> misunderstanding, please feel free to let me know.
>
> Based on the code you have provided, it seems there is a mistake in the
> Test2CallBack. In your code, you called method.BeginInvoke to start the
> thread. However, it has to be method2, because method's thread function
has
> been set to Test1. The following is the modified code. HTH.
>
> Console.WriteLine(String.Format("{0}: {1}: Calling Test2
> asynchronously", DateTime.Now.ToLongTimeString(),
> AppDomain.GetCurrentThreadId))
>
> Dim method2 As New Test2Delegate(AddressOf Test2)
> Dim result As IAsyncResult = method2.BeginInvoke(New
> AsyncCallback(AddressOf Test2Callback), method)
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
- Next message: lance: "how to set description of window service"
- Previous message: jthoward_at_voicenet.com: "Migration - XLA to .NET"
- In reply to: Kevin Yu [MSFT]: "RE: Asynchronous Threading Issue"
- Next in thread: Jon Skeet [C# MVP]: "Re: Asynchronous Threading Issue"
- Reply: Jon Skeet [C# MVP]: "Re: Asynchronous Threading Issue"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|