Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: Preventing an exception from happening when converting to bool Pin
Raphael Adeniji18-Oct-22 1:15
Raphael Adeniji18-Oct-22 1:15 
GeneralRe: Preventing an exception from happening when converting to bool Pin
Richard Andrew x6431-Oct-22 13:38
professionalRichard Andrew x6431-Oct-22 13:38 
QuestionDragging an item from listBox1 and droping the item into listBox2 code does not work(AllowDrop=true) Pin
Programmable Physics7-Oct-22 1:15
Programmable Physics7-Oct-22 1:15 
AnswerRe: Dragging an item from listBox1 and droping the item into listBox2 code does not work(AllowDrop=true) Pin
OriginalGriff7-Oct-22 1:49
mveOriginalGriff7-Oct-22 1:49 
QuestionBasic use of Linklabel tool in winforms gives Exception Handling Error Pin
Programmable Physics6-Oct-22 1:53
Programmable Physics6-Oct-22 1:53 
AnswerRe: Basic use of Linklabel tool in winforms gives Exception Handling Error Pin
CHill606-Oct-22 2:03
mveCHill606-Oct-22 2:03 
AnswerRe: Basic use of Linklabel tool in winforms gives Exception Handling Error Pin
Richard Deeming6-Oct-22 2:11
mveRichard Deeming6-Oct-22 2:11 
QuestionFree licensing solution Pin
Moses Man29-Sep-22 11:45
Moses Man29-Sep-22 11:45 
AnswerRe: Free licensing solution Pin
Gerry Schmitz1-Oct-22 9:01
mveGerry Schmitz1-Oct-22 9:01 
AnswerRe: Free licensing solution Pin
Dave Kreskowiak1-Oct-22 11:48
mveDave Kreskowiak1-Oct-22 11:48 
QuestionC# Service Locator Pin
Kevin Marois28-Sep-22 7:01
professionalKevin Marois28-Sep-22 7:01 
AnswerRe: C# Service Locator Pin
Gerry Schmitz29-Sep-22 7:54
mveGerry Schmitz29-Sep-22 7:54 
GeneralRe: C# Service Locator Pin
Kevin Marois29-Sep-22 11:45
professionalKevin Marois29-Sep-22 11:45 
GeneralRe: C# Service Locator Pin
Richard Deeming29-Sep-22 21:39
mveRichard Deeming29-Sep-22 21:39 
AnswerRe: C# Service Locator Pin
lmoelleb29-Sep-22 22:40
lmoelleb29-Sep-22 22:40 
AnswerRe: C# Service Locator Pin
jochance4-Nov-22 5:48
jochance4-Nov-22 5:48 
QuestionSkype Personal integration with C# Pin
Member 1462363928-Sep-22 4:36
Member 1462363928-Sep-22 4:36 
AnswerRe: Skype Personal integration with C# Pin
Gerry Schmitz28-Sep-22 5:26
mveGerry Schmitz28-Sep-22 5:26 
GeneralRe: Skype Personal integration with C# Pin
Member 1462363928-Sep-22 6:10
Member 1462363928-Sep-22 6:10 
GeneralRe: Skype Personal integration with C# Pin
Victor Nijegorodov28-Sep-22 20:14
Victor Nijegorodov28-Sep-22 20:14 
GeneralRe: Skype Personal integration with C# Pin
Member 1462363928-Sep-22 20:22
Member 1462363928-Sep-22 20:22 
GeneralRe: Skype Personal integration with C# Pin
Mycroft Holmes29-Sep-22 13:18
professionalMycroft Holmes29-Sep-22 13:18 
GeneralRe: Skype Personal integration with C# Pin
Member 1462363929-Sep-22 19:48
Member 1462363929-Sep-22 19:48 
QuestionAsync - await Pin
dataminers20-Sep-22 4:22
dataminers20-Sep-22 4:22 
AnswerRe: Async - await Pin
OriginalGriff20-Sep-22 4:57
mveOriginalGriff20-Sep-22 4:57 
It gets a complicated, but basically the await call spins off a second thread to execute the long running task, and effectively suspends the method until it's complete. But ... the thread that executed await can continue as if the method had finished.

This is handy if you want to run a long task from the main (UI) thread while the UI remains responsive.
For example, if you run this code:
C#
private void MyOtherButton_Click(object sender, EventArgs e)
    {
    Debug.WriteLine("Before Sleep");
    Thread.Sleep(10000);
    Debug.WriteLine("After Sleep");
    }
Your console will print "Before Sleep", wait ten seconds and print "After Sleep" - but your user can't do anything else with your app in the mean time.
But this code:
C#
private async void MyOtherButton_Click(object sender, EventArgs e)
    {
    Debug.WriteLine("Before Sleep");
    await Task.Run(() => Thread.Sleep(10000));
    Debug.WriteLine("After Sleep");
    }
Prints the same things, but your user can carry on working - your UI remains working.

Have a look here: https://www.pluralsight.com/guides/understand-control-flow-async-await[^] - it explains it pretty well, and shows examples.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

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.