3

プログラムがループしており、プログラムを中断したり一時停止したりせずに、リアルタイムの人間との対話を可能にしたいと考えています。

すでに実行中のプログラムのコマンドとして入力を使用できるようにしたいと思います。

基本的に、適切に説明しなかった場合:

-main プログラムはフォアグラウンドで実行されます。

-バックグラウンドで実行される入力を探す二次無限ループ

- 入力時にリターン キー (ReadLine) を押すと、文字列が保存され、別の関数 (Interpreter() など) に送信されます。

-返された入力 (単純なループ) を読み取るようにすべての設定が既に完了していますが、いつでもユーザー入力を許可する方法を理解できません。

編集: スタック オーバーフローは通常、コード内のエラーを解決するためのものであることは知っていますが、それは単純であるべきだとわかっています。どこから始めればよいかわかりません。

編集2:

using System;
using System.Threading;
using SteamKit2;
using SteamTrade;
using System.Collections.Generic;
using System.Text;

namespace SteamBot
{
public class Program
{
    public static void Main(string[] EventArgs)
    {
        LicenseGlobal.Seal.Initialize("MY LICENSE KEY *please ignore this*");

        if (System.IO.File.Exists("settings.json"))
        {

            Configuration config = Configuration.LoadConfiguration("settings.json");
            Log mainLog = new Log(config.MainLog, null);
            foreach (Configuration.BotInfo info in config.Bots)
            {
                mainLog.Info("Launching Bot " + info.DisplayName + "...");
                new Thread(() =>
                {


                    int crashes = 0;
                    while (crashes < 1000)
                    {
                        try
                        {
                            new Bot(info, config.ApiKey, (Bot bot, SteamID sid) =>
                            {

                                return (SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(bot.BotControlClass), new object[] {
                                        bot,
                                        sid
                                    });
                            }, false);

                        }
                        catch (Exception e)
                        {
                            mainLog.Error("Error With Bot: " + e);
                            crashes++;
                        }
                    }
                }).Start();
                Thread.Sleep(5000);
            }
        }
        else
        {
            Console.WriteLine("Configuration File Does not exist. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment");
        }
        Console.WriteLine("Hello World");
        Console.ReadKey();
    }
}
}
4

1 に答える 1