Sunny
7/7/2004 1:34:00 AM
Hi,
If you do not call EndInvoke, there is no way to know that the call was
successful, and there were no exceptions, etc. Or even if the call have
reached the server.
If you do not care, then you can mark the method with [OneWay] attribute.
But, as long as I think about it, if the method was successful and there
were no exceptions, your example should not block. So my suggestion is
first to try with BeginInvoke/EndInvoke, just to see that everything works
and there are no any other problems. After that you can switch to OneWay
method.
Sunny
Tim Smith wrote:
> I see, though in my case the function I call never needs to send any
> results to me - it is a void function for which I do not careful to
> know when it finished. Is there an alternative to EndInvoke or a
> delegate that removes that overhead of the communication coming back?
>
> Sunny <sunny@newsgroups.nospam> wrote in message
> news:<eDhi#p2YEHA.1656@TK2MSFTNGP09.phx.gbl>...
>> Hi,
>>
>> BeginInvoke uses threads from threadpool. Remoting does that as well.
>> Threadpool is limited to 25 threads per process per CPU. If there are no
>> free threads in the pool, BeginInvoke will place next calls in a queue
>> to wait for a thread to be freed. As you never get the results back
>> (calling EndInvoke), it seems that you are never freeing any thread, so
>> the first call succeeds, the next are queued, and never invoked.
>>
>> If you change your code like this:
>>
>> for (int I=0; I<100; I++) {
>> asynchCall.BeginInvoke(I + " logged", null, null);
>> asynchCall.EndInvoke();
>> }
>>
>> everything should be OK. Or create some kind of callback for the
>> delegate, as the code I provide is equal to a sync call.
>>
>> Sunny
>>
>> In article <a7234bb1.0407042127.3910d4af@posting.google.com>,
>> timasmith@hotmail.com says...
>> > My service seems to be losing messages.
>> >
>> > I have a remoting service, running locally which has a method that
>> > sleeps for a second and then does some work
>> >
>> > public void Log (string msg)
>> > {
>> > System.Threading.Thread.Sleep(1000);
>> > StreamWriter streamWriter = new StreamWriter(fileName,true);
>> > streamWriter.WriteLine(msg);
>> > streamWriter.Close();
>> > }
>> >
>> > The sleep represents doing some busy work.
>> >
>> > I have a client which calls the services using an aysnchronous
>> > delegate
>> >
>> > asynchCall = new asynchDelegate(debugService.Log);
>> > for (int i=0; i<100; i++) {
>> > asynchCall.BeginInvoke(i + " logged", null, null);
>> > }
>> >
>> > But only the first couple or few messages are ever received - the
>> > other 90 are lost. If I replace with a synchronous call each message
>> > is logged correctly.
>> >
>> > This suggests that asynchronous calls do not queue in any fashion if
>> > the service is busy?
>> >