Last post Oct 20, 2012 04:49 AM by gerrylowry
Oct 19, 2012 08:52 AM|johnjohn123123|LINK
I have the following method ,, which contains two calls to other methods,, so how i can make the two calls asynchronosly -At the same time- i tired the below code but seems to fail :-
public void async()
Action one = () => firstmethodcall();
Action two = () => secondmethodcall();
Oct 19, 2012 09:20 AM|nijhawan.saurabh|LINK
You can use the ThreadPool.QueueUserWorkItem.
Oct 19, 2012 09:25 AM|johnjohn123123|LINK
thanks for the reply,, but is there an exmaple of how i can use ..
Oct 19, 2012 09:26 AM|gerrylowry|LINK
"Asynchronous Programming with Async and Await (C# and Visual Basic)"
http://msdn.microsoft.com/en-us/vstudio/jj573641.aspx "An Async Primer"
you may find the above articles worth your time.
Oct 19, 2012 09:28 AM|gerrylowry|LINK
P.S.: it's worth thinking about performance costs:
"Async Performance: Understanding the Costs of Async and Await"
Oct 19, 2012 09:54 AM|gerrylowry|LINK
please study this:
"How to: Make Multiple Web Requests in Parallel (C# and Visual Basic)"
Your will note in the above article, three tasks are started, followed by three awaits.
// Await each task.
int length1 = await download1;
int length2 = await download2;
int length3 = await download3;
the three tasks are likely to complete in a somewhat random order.
we do not care ... we simply need them all to complete before moving forward in
http://msdn.microsoft.com/en-us/library/hh156528.aspx "await (C# Reference)"
"The await operator is applied to a task in an asynchronous method to suspend the execution of the method until the awaited task completes. The task represents ongoing work."
P.S.: disclaimer: i'm still trying to understand async/await
myself; at this point, for me, it's still similar to attempting to rub my belly while patting my head ... sometimes my head hurts because i've not mastered the technique.
Oct 19, 2012 10:30 AM|nijhawan.saurabh|LINK
If you are on .NET FW 4.5 (C# 5), you might want to look at this:
Oct 19, 2012 11:18 PM|Paul Linton|LINK
seems to fail
Doesn't compile? What's the compiler error
Throws an exception? What's the exception and where is it thrown
Runtime error? What did you expect, what did you get, what is the code of firstmethodcall and secondmethodcall
Programmer is the art of mastering detail. 'seems to fail' is next to useless as a problem description. Does it fail or does it not? If it fails what is the failure? You must be precise, precise, precise. (Imagine the conversation "Dear Motor mechanic,
there might be something wrong with my car, tell me how to fix it")
Oct 20, 2012 04:49 AM|gerrylowry|LINK
(a) what version(s) of visual studio are you using?
(b) what version(s) of the .NET Framework are you using?
N.B.: async is now a modifier, introduced in
"async (C# Reference)"
imho, it's best of avoid naming a method as async() in order to avoid any possible confusion with the
i say avoid because in c# 5, async is a
"A contextual keyword is used to provide a specific meaning in the code,
but it is not a reserved word in C#.
Some contextual keywords, such as partial and
have special meanings in two or more contexts."
P.S.: found some articles worth reading imho:
author: Jérôme Laban