dotnet/samples

repository·main·Indexed 25 days ago

https://github.com/dotnet/samples

A collection of runnable programs and sample code used across .NET documentation topics. It demonstrates various .NET technologies, features, and toolkits, including asynchronous programming with Async and Await in Visual Basic, Azure App Configuration, Azure Monitor Application Insights, Azure Identity and Resource Management, MetadataLoadContext for assembly inspection, and various .NET Core console applications.

Tokens
105.5K
Snippets
272
Records
589
Agent score
84%

What's inside dotnet-samples

  1. Overview of Wasm Sample: Simple greeting and counter (C#)

    main

    This sample demonstrates how to build a WebAssembly application on top of the mono runtime. It showcases the interoperability between the mono runtime and JavaScript, specifically:

    • Invoking JavaScript unmanaged code (index.html) from the C# managed side (WasmSampleApp.cs).
    • Invoking C# managed code from the JavaScript side.

    The running application allows users to enter a name to modify a greeting message and use a button to increment a counter.

  2. Overview of Async and Await in Visual Basic

    main

    This sample demonstrates asynchronous programming in Visual Basic using Async and Await. These keywords allow developers to write asynchronous code that maintains a logical structure similar to synchronous code, while the compiler handles the underlying complexity.

    The sample specifically illustrates an Async function named GetStringAsync which utilizes HttpClient to download website content without blocking the application thread.

  3. Overview of .NET Source-Generated COM Sample

    main

    This sample demonstrates how to use COM source generators in .NET 8+ to implement an in-process COM server and client. It uses an interface ICalculator (with Add and Subtract methods) where the server provides the implementation and the client consumes it using the Win32 CoCreateInstance method.

    The sample supports two deployment modes:

    1. NativeAOT: Uses the [UnmanagedCallersOnly] attribute to automatically export required native methods.
    2. CoreCLR: Uses the DNNE package to provide the necessary exported functions.
  4. Overview of Orleans Chirper Social Media sample app

    main

    The Orleans Chirper sample is a social media platform implementation demonstrating a pub/sub system where users send short text messages called "Chirps" to followers.

    The sample is split into two applications:

    • Chirper.Server: Hosts the Orleans runtime and all grains.
    • Chirper.Client: Hosts an Orleans client and provides a terminal interface.

    Key Orleans features demonstrated include:

    • Grain persistence: Storing grain state in a database (uses in-memory persistence by default).
    • Reentrant grains: Allowing multiple calls to interleave concurrently.
    • Grain observers: Sending push messages back to clients.
  5. Overview of Orleans TicTacToe web-based game

    main

    This sample is a web-based Tic-tac-toe game implemented as a single project (TicTacToe.csproj). It uses the .NET Generic Host to host an ASP.NET Core MVC application alongside Orleans.

    The application utilizes three types of Orleans grains:

    • PlayerGrain: Represents a player. Allows joining/leaving games, updating properties, and retrieving game history.
    • GameGrain: Represents an individual game session and contains the game logic. Allows clients to make moves and view the current board state.
    • PairingGrain: Maintains a list of currently available games that players can join.