I using ModuleInit.Fody for create code that should be invoke on load of assembly. In this code I need do some operation in task. Unfortunately there is problem with this code... code inside the task is not fired. when i used this same code after module initialization work like a charm.
Some testable code
public static class ModuleInitializer
{
public static AsyncCallback callback;
public static void Initialize()
{
callback = ar => Console.WriteLine("Result");
ConsoleThread(() => ModuleInitializer.RunThread(1));
Console.WriteLine("Compleate");
Console.ReadKey();
}
public static void ConsoleThread(Action inputFunct)
{
IAsyncResult result = inputFunct.BeginInvoke(callback, null);
}
public static void RunThread(int i)
{
Console.WriteLine($"Thread {i}");
}
public static void Test()
{
}
}
and program.cs
class Program
{
static void Main(string[] args)
{
ModuleInitializer.Test();
}
}
Do anyone know how to create code, that will be run in second thread or it is impossible? Maybe someone known any other way to create init code that could be run in thread?
Regards Szymon Szczepański