Thursday 23 June 2022

Building a serverless web app

https://docs.microsoft.com/en-us/labs/build2018/serverlesswebapp/


https://www.google.com/search?q=serverless+web+app+tutorial+c%23&oq=serverless&aqs=chrome.4.69i57j69i60l3j35i39l2j0i131i433i512j0i512.6810j1j4&client=ms-android-samsung-gs-rev1&sourceid=chrome-mobile&ie=UTF-8#fpstate=ive&vld=cid:2293a4cb,vid:idR4S7BXYns,st:0

### What is blazor?

### What is blazor?


```
C:\Users\matthew.oh>dotnet --list-sdks
6.0.300 [C:\Program Files\dotnet\sdk]
```



q. what is blazor?
ans. using c# as javascript

q. web assembly?
ans. web compiler

q. SignalR connection?
ans. connection between client and server
when button clicks on client side, HTML Diff sent from server through SignalR connection

blazor application + server hosting model
C:\Users\matthew.oh>dotnet --list-sdks


## Blazor tutorial



separate .cs files or inline in your Razor components.

### todo blazorapp
@expression() to add a c# statement inline with HTML
@code
@functions
@Page
@bind

```
c:\Works\BlazorApp\BlazorApp>dotnet new razorcomponent -n Todo -o Pages
The template "Razor Component" was created successfully.
```




Thursday 2 June 2022

c# wpf keep ui response not working (c# thread )

https://docs.microsoft.com/en-us/windows/uwp/debug-test-perf/keep-the-ui-thread-responsive


Above url says that don't put UI things with main working function.

// Perform background work here. // Don't directly access UI elements from this method.

The key point is let sub function be called inside:

await Task.Run(() => 'your function working long');




If you mix up main thread and ui thread, below error happens.
the calling thread cannot access this object




UI part code should be seprated from 'async work thread'. Otherwise you have error.



Read related article thoroughly:

https://stackoverflow.com/questions/9732709/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it



Below code will not work for showing spinner
            uiBefore();
            ConnectionChanged();
            uiAfter();

Below code works
            uiBefore();
            await Task.Run(() =>
            {
                ConnectionChanged();
            });
            uiAfter();


        private void uiBefore()
        {
            faSpinner.Visibility = Visibility.Visible;
        }

        private void uiAfter()
        {
            faSpinner.Visibility = Visibility.Collapsed;
        }

It seems funciton inside await Task.Run() doesn't have to be async function. Only the parent function needs to be async. Below code works.