I am trying to allow two of my methods to run every ms in the background of my script. However, when my method's are called, the everything else stops running while they are active, I believe this is because at the end of my method I call them both again. I need to run these every ms so everything works correctly, while also allowing everything else to run. Here is the code:
public async Task MuteUpdate()
{
//UPDATE `mutes` SET MuteUntil = MuteUntil - 1
string connstr = "Server=echstreme.de;Port=3306;Database=c1Look;Uid=c1Look;Pwd=Redacted;SSL Mode =None";
MySqlConnection conn = new MySqlConnection(connstr);
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand(SQLMUteRemove, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
MuteRead();
MuteUpdate();
}
public async Task MuteRead()
{
string connStr = "Server=echstreme.de;Port=3306;Database=c1Look;Uid=c1Look;Pwd=redactedINfo;SSL Mode =None";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `mutes` WHERE MuteUntil <= 0", conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ulong id = Convert.ToUInt64(rdr[1]);
Context.Guild.GetUser(id);
await SendLog("__Mute Manager__", "**Member** | <@" + rdr[1] + ">\n **Punishment** | UNMUTE" + "\n **Punished by** | <@" + rdr[4] + ">");
sqlQuery = "DELETE FROM `mutes` WHERE `UserID` = " + rdr[1] + ";";
await Context.Guild.GetUser(id).RemoveRoleAsync(876561161062076416);
}
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}