Free Source Code: Learn C# Async Programming & File Management





โปรเจกต์นี้พัฒนาด้วย Visual Studio 2022
🖥️✨ อาจารย์แนะนำให้ติดตั้งพร้อมกับ .NET 8
🚀 หรือเวอร์ชันใหม่ล่าสุด
🔄 ตามวิดีโอสอนฟรีด้านล่างนี้เลยครับ 🎬👇

This project was developed using Visual Studio 2022.
I recommend installing it along with .NET 8
or the latest version.
Check out the free tutorial video below! 🎥👇


Here’s an example of Visual Basic .NET source code in the Main module of the project:

// See https://aka.ms/new-console-template for more information
// Console.WriteLine("Hello, World!");

// 1. Modern C# (.NET 8) file-scoped namespace syntax:
/*
    namespace CSEnterpriseInventory;
    public static class Program 
    {
        // Your code here
    }
*/

// 2. Traditional C# namespace syntax:
/*
    namespace CSEnterpriseInventory
    {
        public static class Program 
        {
            // Your code here
        }
    }
*/

/*
Both work the same, but the first one (file-scoped namespace) 
is more modern and recommended in .NET 8. 
It reduces nesting and makes the code cleaner. 
The namespace helps organize your code and prevent naming conflicts, 
just like in your VB.NET version.
*/

using CSEnterpriseInventory;

namespace EnterpriseInventory;

/// <summary>
/// Main entry point for the Enterprise Grade Inventory Management System
/// </summary>
public static class Program
{
    /// <summary>
    /// Entry point of the application
    /// </summary>
    public static void Main(string[] args)
    {
        try
        {
            // Display application title and header
            Console.WriteLine("Enterprise Grade Inventory Management System");
            Console.WriteLine("----------------------------------------");
            Console.WriteLine();

            // Synchronously execute the asynchronous application initialization
            InitializeApplicationAsync().Wait();
        }
        catch (OperationCanceledException ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(Environment.NewLine + "Program terminated by user.");
            Environment.Exit(1);

            // Environment.Exit(1) is a method in .NET that immediately terminates
            // the current running application with a specific exit code.
            // In this context: 1 indicates an abnormal termination or error condition
            // It forcefully stops the application
        }
        catch (Exception ex)
        {
            Console.WriteLine(Environment.NewLine + "Critical Error");
            Console.WriteLine("--------------");
            Console.WriteLine("An unexpected error has occurred:");
            Console.WriteLine(ex.Message);
            Console.WriteLine(Environment.NewLine + "The application needs to close.");
            Console.WriteLine("Please contact system administrator if this persists.");
            Environment.Exit(1);
        }

        // Prompt user to press any key before application closes
        Console.WriteLine(Environment.NewLine + "Press any key to exit...");
        Console.ReadKey();
    }

    /// <summary>
    /// Asynchronous method to initialize the entire application
    /// </summary>
    private static async Task InitializeApplicationAsync()
    {
        // Attempt system initialization with retry mechanism
        await InitializeWithRetryAsync();

        // Start the main program loop (menu system)
        await MainProgramLoopAsync();
    }

    /// <summary>
    /// Implements a retry mechanism for system initialization
    /// </summary>
    private static async Task InitializeWithRetryAsync()
    {
        // Maximum number of initialization attempts
        const int MaxRetries = 3;
        int retryCount = 0;

        while (true)
        {
            try
            {
                // Attempt to initialize the system
                await SystemInitialization.InitializeSystemAsync();

                // Verify the system's integrity
                if (await SystemInitialization.VerifySystemIntegrityAsync())
                {
                    // System initialization successful
                    Console.WriteLine("System verification passed. Ready to start.");
                    Console.WriteLine(Environment.NewLine + "Press any key to continue...");
                    Console.ReadKey(true);  // Pause for user acknowledgment
                    break;  // Exit retry loop if successful
                }
                else
                {
                    // Throw exception if system verification fails
                    throw new Exception("System verification failed.");
                }
            }
            catch (Exception ex)
            {
                // Increment retry counter
                retryCount++;

                // Check if maximum retry attempts have been reached
                if (retryCount >= MaxRetries)
                {
                    Console.WriteLine(Environment.NewLine + "Initialization Failed");
                    Console.WriteLine("---------------------");
                    Console.WriteLine($"Failed to initialize after {MaxRetries} attempts.");
                    Console.WriteLine("Error: " + ex.Message);
                    throw;  // Throw final error if all attempts fail
                }

                // Inform user about retry attempt
                Console.WriteLine(Environment.NewLine + $"Initialization attempt {retryCount} of {MaxRetries} failed.");
                Console.WriteLine("Press any key to retry or Esc to cancel...");

                // Get user input for retry or cancel
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Escape)
                {
                    // Allow user to cancel initialization
                    throw new OperationCanceledException("Initialization cancelled by user.");
                }
            }
        }
    }

    /// <summary>
    /// Main program loop to display and handle the menu system
    /// </summary>
    private static async Task MainProgramLoopAsync()
    {
        // Call the main menu display method from MenuSystem module
        // await MenuSystem.DisplayMainMenuAsync();
        await Task.CompletedTask;
    }
}

🚀 Free Source Code: Learn C# Async Programming & File Management

🚀 แจกฟรี! โปรเจกต์ C#: การเขียนโปรแกรมอะซิงโครนัส & การจัดการไฟล์ และโฟลเดอร์

🚀 Free C# Source Code: Mastering Async Programming & File Management!

Are you a beginner looking to understand asynchronous programming, file handling, and folder management in C#? This free source code is a great learning resource to strengthen your fundamentals! Let’s explore what you’ll gain from studying this structured and well-commented code.


🎯 What Will You Learn?

✅ Folder & File Management

  • Dynamically create folders using Directory.CreateDirectory().
  • Generate CSV files with predefined headers.
  • Understand the importance of file structure organization.

✅ Error Handling & Logging

  • Use try-catch blocks to handle exceptions gracefully.
  • Manage common errors like UnauthorizedAccessException and IOException.

✅ Asynchronous Programming

  • Use async & await to perform non-blocking file operations.
  • Prevent UI freezes and lagging in large applications.

✅ Structured Data Storage

  • Store tabular data using CSV files.
  • Maintain data consistency with properly formatted headers.

✅ Basic System Verification Techniques

  • Validate file existence before accessing them.
  • Implement a retry mechanism for system initialization.

✅ Backup & Data Safety

  • Automatically backup files before modification to prevent data loss.
  • Use timestamped directories for version control.


This is a great resource for beginners to practice real-world programming concepts before diving into enterprise applications. 💡


📌 Note 1: This free source code is for members only.
📌 Note 2: This free Visual Studio 2022 project is for members only.


ขอบคุณสำหรับการสนันสนุน สมาชิกสามารถดาวน์โหลดโปรเจกต์ได้ที่ลิงค์นี้

Thank you for your support! You can download the project at this link

For members only!

Download project


💬 พูดคุยกับผมที่...
► LINE OA : https://lin.ee/ApE56xD
► Facebook : https://www.facebook.com/CodeAMinute

📺 ติดตามช่อง YouTube
https://www.youtube.com/@iBasskung
https://www.youtube.com/@iBasskungAcademy
► TikTok : https://www.tiktok.com/@codeaminute

📖 ดูหลักสูตรทั้งหมด: https://bit.ly/3lXWoj2

Udemy profile : https://www.udemy.com/user/tanin-sangngam


#CodeAMinute #iBasskung #CEO #โปรแกรมเมอร์ #สอนเขียนโปรแกรม #สอนทำโปรเจกต์ #เรียนซีชาร์ป #พัฒนาSoftware #ซอฟต์แวร์องค์กร #เขียนโปรแกรม #VisualStudio2022 #โปรแกรมเมอร์ไทย #ระบบจัดการสินค้า #เขียนโค้ดให้เป็น #เรียนออนไลน์ #CSharp #CSharpDevelopment #SoftwareEngineering #EnterpriseSoftware #ProgrammingForBeginners #LearnToCode #VisualStudio #AsyncProgramming #FileManagement #SoftwareDesign #DotNet

Comments