Calling a service from a windows client

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'll try and keep this short! When calling a web service async. I can use
the Beginxxx method on the generated proxy. But if me 'service' was not a web
service but something else, is it better to create a new Thread for the call
or use the threadpool; baring in mind that the service call could take a
little while (between 1 and 10 seconds, depends on the amount of data
returned!)

Thanks for your help.
 
Hi,

You can create a delegate with the signature matching that of a method to be
run in the background, initialize the delegate with the method to be invoked
and use the delegate's BeginInvoke method to achieve the same result.

Actually, both the Beginxxx methods and the delegate's BeginInvoke take a
thread from the thread pool behind the scenes and execute the code on that
thread.
 
Thanks Dmitriy, but why are web services called using a thread from the
threadpool? Isn't a web service call considered a 'long running' operation?
Or is it ok to say that *most* of the time they are pretty quick so it
doesn't really matter that it is using up a thread from the thread pool?



Dmitriy Lapshin said:
Hi,

You can create a delegate with the signature matching that of a method to be
run in the background, initialize the delegate with the method to be invoked
and use the delegate's BeginInvoke method to achieve the same result.

Actually, both the Beginxxx methods and the delegate's BeginInvoke take a
thread from the thread pool behind the scenes and execute the code on that
thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Gravy said:
Hi

I'll try and keep this short! When calling a web service async. I can use
the Beginxxx method on the generated proxy. But if me 'service' was not a
web
service but something else, is it better to create a new Thread for the
call
or use the threadpool; baring in mind that the service call could take a
little while (between 1 and 10 seconds, depends on the amount of data
returned!)

Thanks for your help.
 
Yes, it is considered as a long-running operation. But this is hardly an
issue for a desktop application, for which it is unlikely to have more Web
service call in parallel than the number of threads in the thread pool.
Still, even putting scalability in the picture, it is not advisable to
create more threads than a certain threshold value depending on the number
of physical CPUs (and probably their hyperthreading capability). And in this
sense, a thread from the pool is absolutely similar to a manually created
thread - so why bother with managing threads manually when this has been
done for you by the Redmontonians :-)

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Gravy said:
Thanks Dmitriy, but why are web services called using a thread from the
threadpool? Isn't a web service call considered a 'long running'
operation?
Or is it ok to say that *most* of the time they are pretty quick so it
doesn't really matter that it is using up a thread from the thread pool?



Dmitriy Lapshin said:
Hi,

You can create a delegate with the signature matching that of a method to
be
run in the background, initialize the delegate with the method to be
invoked
and use the delegate's BeginInvoke method to achieve the same result.

Actually, both the Beginxxx methods and the delegate's BeginInvoke take a
thread from the thread pool behind the scenes and execute the code on
that
thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Gravy said:
Hi

I'll try and keep this short! When calling a web service async. I can
use
the Beginxxx method on the generated proxy. But if me 'service' was not
a
web
service but something else, is it better to create a new Thread for the
call
or use the threadpool; baring in mind that the service call could take
a
little while (between 1 and 10 seconds, depends on the amount of data
returned!)

Thanks for your help.
 
That was I was thinking (honest), I just wanted someone to confirm it.

Thanks

Dmitriy Lapshin said:
Yes, it is considered as a long-running operation. But this is hardly an
issue for a desktop application, for which it is unlikely to have more Web
service call in parallel than the number of threads in the thread pool.
Still, even putting scalability in the picture, it is not advisable to
create more threads than a certain threshold value depending on the number
of physical CPUs (and probably their hyperthreading capability). And in this
sense, a thread from the pool is absolutely similar to a manually created
thread - so why bother with managing threads manually when this has been
done for you by the Redmontonians :-)

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Gravy said:
Thanks Dmitriy, but why are web services called using a thread from the
threadpool? Isn't a web service call considered a 'long running'
operation?
Or is it ok to say that *most* of the time they are pretty quick so it
doesn't really matter that it is using up a thread from the thread pool?



Dmitriy Lapshin said:
Hi,

You can create a delegate with the signature matching that of a method to
be
run in the background, initialize the delegate with the method to be
invoked
and use the delegate's BeginInvoke method to achieve the same result.

Actually, both the Beginxxx methods and the delegate's BeginInvoke take a
thread from the thread pool behind the scenes and execute the code on
that
thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Hi

I'll try and keep this short! When calling a web service async. I can
use
the Beginxxx method on the generated proxy. But if me 'service' was not
a
web
service but something else, is it better to create a new Thread for the
call
or use the threadpool; baring in mind that the service call could take
a
little while (between 1 and 10 seconds, depends on the amount of data
returned!)

Thanks for your help.
 
Back
Top