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.


Sunday, 29 May 2022

WPF project - db connector

https://www.guru99.com/c-sharp-access-database.html

https://www.youtube.com/watch?v=hsfLtC4Ikvw

WPF tutorial

https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-wpf?view=vs-2022

So easy to release:

  • No IIS publish
  • No admin permission to install the program
  • UI can be easily updated through XAML file.


More tutorials:

https://docs.microsoft.com/en-us/dotnet/desktop/wpf/getting-started/wpf-walkthroughs?view=netframeworkdesktop-4.8

I choose the first one.

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/bb546972(v=vs.100)

This tutorial shows TreeView and two ListViews.

Code converted to c# by: https://converter.telerik.com/



<ListView Name="listView1" 

        ItemsSource="{Binding Path=SelectedItem.SubFolders, ElementName=treeView1, Mode=OneWay}" 

        Grid.Column="1" 

        Grid.RowSpan="1" />


        <ListView Name="listView2" 

        ItemsSource="{Binding Path=SelectedItem.Files, ElementName=treeView1, Mode=OneWay}" 

        Grid.Column="1" 

        Grid.Row="1" />

Friday, 27 May 2022

visual code + ssh





You can then open any folder or workspace on the remote machine using File > Open... or File > Open Workspace... just as you would locally!