Giter Club home page Giter Club logo

commandrunner's Introduction

CommandRunner

汎用コマンドバッファリングと実行の基本処理 / Basic process for generic command buffering and execution

使い方 / how to use

使い方は以下の通りです / The usage is as follows

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading;

namespace Takap.Ulitity
{
    internal class AppMain
    {
        [DllImport("kernel32.dll")]
        public static extern uint GetCurrentThreadId();

        private static void Main(string[] args)
        {
            // コマンド実行用のオブジェクトの作成
            // Create object for command execution
            CommandRunner _runner = new();
            try
            {
                // コマンドが終了したときのコールバックを設定
                // Set callback when command terminates
                _runner.CommandCompleted += c =>
                {
                    Trace.WriteLine(c.ToString());
                    foreach (var info in c.GetCommandInfo().GetHistory())
                    {
                        Trace.WriteLine($"[{GetCurrentThreadId():D6}] {info}");
                    }
                };

                // 同時実行数を2に設定
                // Set concurrency to 2
                _runner.ConcurrentCount = 2;

                // サンプルコマンドを作成して順次登録
                // Create sample commands and register them sequentially
                for (int i = 0; i < 100; i++)
                {
                    // 少し時間のかかる処理
                    // Slightly time-consuming process
                    var command1 = new SampleCommand1()
                    {
                        ArgsJsonString = JsonSerializer.Serialize(new SampleArgs() { ID = i })
                    };

                    // コマンドを実行キューに登録
                    // register the command in the execution queue
                    // 
                    // コマンドキューには最大容量が無いので詰み過ぎがある場合制限を追加で実装する
                    // Command queue does not have a maximum capacity, 
                    // so if it is overstuffed, implement an additional limit
                    _runner.Entry(command1);
                }

                Thread.Sleep(-1);
            }
            finally
            {
                // 使い終わったら破棄する
                // Discard when finished using.
                using (_runner) { }
            }
        }
    }
}

commandrunner's People

Contributors

taka414 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.