Showing posts with label C# Tutorials. Show all posts
Showing posts with label C# Tutorials. Show all posts

Blazor hosting module_First Blazor Application

     When we create our blazor application using visual studio 2019 then we don’t see blazor WebAssembly App template because it is still in under preview, but still we can install it by using the following command. We can execute this command either from the Package Manager Console in Visual Studio or from the command prompt.Following is the Google link to see the latest version of Blazor web assembly
E    execute the following command to install the Blazor WebAssembly App template
WebAssembly hosting model benefits

The Blazor WebAssembly hosting model offers several benefits:
Ø  There's no .NET server-side dependency means server connection not required.
Ø  Client resources and capabilities are used.
Ø  Workload is from the server to the client.
Ø  For hosting the application we don’t need any host app even we can host on our host(for example, serving the app from azure or a CDN).
There are downsides to Blazor WebAssembly hosting:
Ø  The app is restricted to the capabilities of the browser.
Ø  Capable client hardware and software (for example, WebAssembly support) is required.
Ø  Download size is larger, and the very 1st request apps take longer time to load.

Blazor Server hosting model benefits :

The Blazor Server hosting model offers several benefits:
Ø  Download size is smaller than a Blazor WebAssembly the app, and the application loads much faster.
Ø  The app takes full advantage of server capabilities.
Ø  .NET Core on the server is used to run the app, so existing .NET tooling, such as debugging, works as expected.
Ø  Blazor Server apps work with browsers that don't support WebAssembly. There are downsides to Blazor Server hosting:
Ø  Higher latency usually exists because of the roundtrip of server.
Ø  There's no offline support. If the client connection fails, the app stops working.
Ø  Scalability is challenging for apps with many users.
Ø  An ASP.NET Core server is required to serve the app.

What is Blazor and Setup for Blazor

Blazor Introduction
1.   In current days we create a web application using server-side as well as client-side programming knowledge.
2.   For server-side development, we use language like, C#, PHP, Java, etc, and for the client-side development, we use language like, Angular, react, etc, so for making a successful web application we have to learn both sides programming languages.
3.   To overcome this problem Blazor came in the market , where write C# on the server-side as well as client-side hence it is a more interesting aspect of development.
4.   Blazor is developed by the Microsoft, and it’s a framework for creating a client-side web user interface using a dot net.
5.   Blazor comes at top of core and it has all the new features of web development.
6.   Blazor doesn’t need any plug-in unlike flash and silver light, it works on all the browsers.        

How browser understand C# and execute the code
1.   As we know browser understand only JavaScript, then how browser execute C# code in the browser and the answer is with using WebAssembly.
2.   Basically, we can run any type of code with using Web Assembly, similar way Blazor can run C# code on the browser using Web Assembly, and executing code with web Assembly is secure like other client-side application.
Setup for Blazor development
For developing a Blazor application we need the following things to install in our machine.

1. Dot net core SDK 3.1 or later
    Url to download:-
 2. Visual studio 2019
       Visual studio code
       Dot net core CLI
Following is the command For checking the version.
                     dotnet --list-sdks
For creating a Blazor application we should have knowledge on the following languages

How to use multi threading in a For loop

How to use multi threading in a For loop
class Program

    static int workingCounter = 0;
    static int workingLimit = 10;
    static int processedCounter = 0;

    static void Main(string[] args)
        string[] files = Directory.GetFiles("C:\\Temp");
        int checkCount = files.Length;
        foreach (string file in files)
            //wait for free limit...
            while (workingCounter >= workingLimit)
            workingCounter += 1;
            ParameterizedThreadStart pts = new ParameterizedThreadStart(ProcessFile);
            Thread th = new Thread(pts);
        //wait for all threads to complete...
        while (processedCounter< checkCount)
        Console.WriteLine("Work completed!");

    static void ProcessFile(object file)
            Console.WriteLine(DateTime.Now.ToString() + " recieved: " + file + " thread count is: " + workingCounter.ToString());
            //make some sleep for demo...
        catch (Exception ex)
            //handle your exception...
            string exMsg = ex.Message;
            Interlocked.Decrement(ref workingCounter);
            Interlocked.Increment(ref processedCounter);