スレッドボットの状況を管理しようとしています。後でアクセスするために辞書に追加したいのですが(シャットダウン、一時停止、変数の受け渡し)null
、ボットが起動した後でも常に取得します(null
変数はtemp_bot
)。
private static
Dictionary<string, Bot> BotsOnline = new Dictionary<string, Bot>();
Bot temp_bot;
new Thread(
() =>
{
int crashes = 0;
while (crashes < 1000)
{
try
{
temp_bot = new Bot(config, sMessage, ConvertStrDic(offeredItems),
ConvertStrDic(requestedItems), config.ApiKey,
(Bot bot, SteamID sid) =>
{
return (SteamBot.UserHandler)System.Activator.CreateInstance(
Type.GetType(bot.BotControlClass), new object[] { bot, sid });
},
false);
}
catch (Exception e)
{
Console.WriteLine("Error With Bot: " + e);
crashes++;
}
}
}).Start();
//wait for bot to login
while (temp_bot == null || !temp_bot.IsLoggedIn)
{
Thread.Sleep(1000);
}
//add bot to dictionary
if (temp_bot.IsLoggedIn)
{
BOTSdictionary.Add(username, temp_bot);
}