Dotnet

Built on .NET Framework 4.5.2. Then downgraded to 4.0...

Recently I had to build a Windows app.

I heard .NET 4.5 added the new async syntax, so.. might as well, I went with 4.5.2. Oh…… it’s incredibly convenient.!!

async and await are the two important parts. Especially in UI programs, they make syncing between the background thread and the main thread easy.

Below is code that takes an id/pwd and authenticates against a server.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
    string id = tbEmail.Text;
    string pwd = tbPassword.Password;

    SetControlEnableState(false);
    bool isSuccess = await Task.Run<bool>(() =>
    {
        try
        {
                    // 여기가 네트워크 통신을 하는 부분이다.
            _dataCore.DoLogin(id, pwd);
            return true;
        }
        catch (Exception x)
        {
            ErrorHandler.ErrorDump(x, true);
            return false;
        }
        });

    if (!isSuccess)
    {
        SetControlEnableState(true);
        return;
    }
}

As you can see, the login is handled entirely in the client event… with no separate thread synchronization..

Then today I ran tests… Not many PCs.. have .NET Framework 4.5.. installed…..

… so.. I rewrote it on 4.0.. with BackgroundWorker…

Ugh… (the program only has three screens, thankfully)