Click here to Skip to main content
15,890,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For some reason, I have to simulate an asynchronous operation.
I have to admit it, I am not strong on it.
Say I have:
C#
Console.WriteLine("Hello World!");

How to convert it to asynchronous one?
IAsyncResult or BeginInvoke?
I NEED code.

Thank you.
Posted
Updated 13-Nov-14 4:45am
v2
Comments
BillWoodruff 13-Nov-14 10:50am    
And you want to do this in ... WinForms ... WPF ... ASP.NET ?
[no name] 13-Nov-14 11:03am    
WPF, the code is already in a async/await task. I want to simulate the third party API with a few lines code.
Sergey Alexandrovich Kryukov 13-Nov-14 13:20pm    
It depends on what do you mean by "asynchronous operation". First of all, you need to understand that anything updating the UI is always synchronized with the thread of this UI, by putting it in an event queue...
—SA
Richard MacCutchan 13-Nov-14 10:59am    
You cannot easily simulate an asynchronous operation without doing it asynchronously.

1 solution

You will have to create a container for this method, since this method is present in a .NET library itself, you cannot edit it. You can however, create a container method and apply a few things to it.

async[^] modifier is used to tell that this method is asynchronous. await[^] is used to stop the execution until an async method is executed.

Read more on this document[^]. Also read this question[^].
 
Share this answer
 
Comments
[no name] 13-Nov-14 10:47am    
I don't want to use async/await. Is there a way to do it?
Afzaal Ahmad Zeeshan 13-Nov-14 10:54am    
No without that, No!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900