それらを並行して実行したい場合は、 Parallel.Invokeを使用できます。
while (true)
{
Parallel.Invoke(BinaryConversion, ValidateEmails);
System.Threading.Thread.Sleep(1000);
}
あなたの編集に基づいて、より長い例:
namespace CSharp
{
using System;
using System.Threading.Tasks;
class Program
{
static void Main()
{
bool executebinary = true;
bool emailvalidation = false;
while (true)
{
Parallel.Invoke(
() =>
{
if (executebinary)
{
BinaryConversion();
}
},
() =>
{
if (emailvalidation)
{
ValidateEmails();
}
});
System.Threading.Thread.Sleep(1000);
}
}
private static void ValidateEmails()
{
}
private static void BinaryConversion()
{
}
}
}
あなたのコメントに基づいて、両方が他方からの干渉なしで同時に実行されています:
namespace CSharp
{
using System;
using System.Threading.Tasks;
class Program
{
static void Main()
{
bool executebinary = true;
bool emailvalidation = false;
Parallel.Invoke(
() =>
{
while(true) if (executebinary) BinaryConversion();
},
() =>
{
while(true) if (emailvalidation) ValidateEmails();
});
}
}
private static void ValidateEmails()
{
}
private static void BinaryConversion()
{
}
}
}