Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: web control browser Pin
OriginalGriff25-Jan-17 2:56
mveOriginalGriff25-Jan-17 2:56 
QuestionMessage Closed Pin
25-Jan-17 1:18
professionalJackson Savitraz25-Jan-17 1:18 
AnswerRe: Fuzzy IndexOf using Bitap Algorithm Pin
OriginalGriff25-Jan-17 1:52
mveOriginalGriff25-Jan-17 1:52 
QuestionAppending data to existing excel file using C# Pin
Member 1296649424-Jan-17 15:34
Member 1296649424-Jan-17 15:34 
AnswerRe: Appending data to existing excel file using C# Pin
Ralf Meier24-Jan-17 22:18
mveRalf Meier24-Jan-17 22:18 
AnswerRe: Appending data to existing excel file using C# Pin
Richard MacCutchan24-Jan-17 22:34
mveRichard MacCutchan24-Jan-17 22:34 
AnswerRe: Appending data to existing excel file using C# Pin
Patrice T25-Jan-17 10:55
mvePatrice T25-Jan-17 10:55 
QuestionAwait - Async not so simple to use? Pin
Richard Andrew x6424-Jan-17 12:24
professionalRichard Andrew x6424-Jan-17 12:24 
I have a form Form1 on which is a listbox and a button.

Consider the following code, and read the problem I am having with it below:

private async void button1_Click(object sender, EventArgs e)
{
    listBox.Items.AddRange(new object[] {"Hello", "There", "Code", "Project."});
    await PerformLengthyTask();
}

private async Task<bool> PerformLengthyTask()
{
    Thread.Sleep(5000);
    return true;
}

What I THOUGHT would happen when I clicked the button:
The new items would appear instantly in the listbox because while the UI thread is waiting for the PerformLengthyTask function, it is free to pump messages and keep the UI responsive. Roll eyes | :rolleyes:

What ACTUALLY happens when I click the button:
The new items do not appear in the listbox until after PerformLengthyTask returns. Confused | :confused:
And also, the form itself is frozen.

What is it that I do not understand about async methods that is causing me this confusion?



The difficult we do right away...
...the impossible takes slightly longer.

AnswerRe: Await - Async not so simple to use? Pin
Nathan Minier24-Jan-17 14:22
professionalNathan Minier24-Jan-17 14:22 
GeneralRe: Await - Async not so simple to use? Pin
Richard Andrew x6425-Jan-17 1:41
professionalRichard Andrew x6425-Jan-17 1:41 
AnswerRe: Await - Async not so simple to use? Pin
Jon McKee24-Jan-17 17:53
professionalJon McKee24-Jan-17 17:53 
GeneralRe: Await - Async not so simple to use? Pin
Richard Andrew x6425-Jan-17 1:42
professionalRichard Andrew x6425-Jan-17 1:42 
SuggestionRe: Await - Async not so simple to use? Pin
Richard Deeming25-Jan-17 3:09
mveRichard Deeming25-Jan-17 3:09 
GeneralRe: Await - Async not so simple to use? Pin
Jon McKee25-Jan-17 9:34
professionalJon McKee25-Jan-17 9:34 
GeneralRe: Await - Async not so simple to use? Pin
Richard Deeming25-Jan-17 10:23
mveRichard Deeming25-Jan-17 10:23 
GeneralRe: Await - Async not so simple to use? Pin
Jon McKee25-Jan-17 10:49
professionalJon McKee25-Jan-17 10:49 
AnswerRe: Await - Async not so simple to use? Pin
Graeme_Grant25-Jan-17 1:31
mvaGraeme_Grant25-Jan-17 1:31 
AnswerRe: Await - Async not so simple to use? Pin
Richard Deeming25-Jan-17 3:12
mveRichard Deeming25-Jan-17 3:12 
GeneralRe: Await - Async not so simple to use? Pin
Richard Andrew x6425-Jan-17 10:08
professionalRichard Andrew x6425-Jan-17 10:08 
QuestionDelegates Pin
Member 1202181724-Jan-17 2:13
Member 1202181724-Jan-17 2:13 
AnswerRe: Delegates Pin
Richard Deeming24-Jan-17 2:20
mveRichard Deeming24-Jan-17 2:20 
AnswerRe: Delegates Pin
OriginalGriff24-Jan-17 2:26
mveOriginalGriff24-Jan-17 2:26 
QuestionPlz Send Me The Simpler Answer to connect with SSIS And SSRS Both In any Version fo the Excell Pin
Member 889223723-Jan-17 23:45
Member 889223723-Jan-17 23:45 
GeneralRe: Plz Send Me The Simpler Answer to connect with SSIS And SSRS Both In any Version fo the Excell Pin
Richard MacCutchan24-Jan-17 0:42
mveRichard MacCutchan24-Jan-17 0:42 
Questionnumber converter Pin
ab_ayo23-Jan-17 1:51
ab_ayo23-Jan-17 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.