I'm trying to preload assemblies in a background thread and it seems that when the PreLoadAssemblies function is being called nothing happen and like the thread is dead or something (but I do see the thread in the threads list). When I run the code in single threaded environment, it's works fine.
Here is where I create the background call:
BackgroundWorker backgroundWorker = new BackgroundWorker();
//[Threaded]
private void InitlaizePoint()
{
backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundInitalization);
backgroundWorker.RunWorkerAsync();
}
Here is the background initialization function. It stops (meaning, nothing happen and I see my dialog window progress bar running "on empty") after I try to step-in through the PReLoadAssemblies).
private void BackgroundInitalization(object sender, DoWorkEventArgs e)
{
try
{
PreLoadAssemblies();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
here is how preloadassemblies looks like:
private static void PreLoadAssemblies()
{
//statusController.PublishStatus("pre-loading assemblies");
var missingAssemblies = new ArrayList();
var loadedAssemblies = new ArrayList();
LoadDependencies(Assembly.GetExecutingAssembly().GetName(), missingAssemblies, loadedAssemblies);
}
private static void LoadDependencies(AssemblyName name, ArrayList missingAssemblies, ArrayList loadedAssemblies)
{
try
{
//statusController.PublishStatus("Loading dependencies");
Assembly a = Assembly.Load(name);
loadedAssemblies.Add(name.FullName);
foreach (AssemblyName depends in a.GetReferencedAssemblies())
{
if (!IsAssemblyLoaded(depends.FullName, loadedAssemblies))
LoadDependencies(depends, missingAssemblies, loadedAssemblies);
}
}
catch (Exception)
{
missingAssemblies.Add(name);
}
}
private static bool IsAssemblyLoaded(String name, ArrayList preloadedAssemblies)
{
if (preloadedAssemblies.IndexOf(name) == -1)
return false;
return true;
}
Let me know if you have any idea.
Thanks