I have created an application that will dynamically load other DLLs (plugins).
The new plugin is a winform with an embedded IE Browser.

I am wanting to have the form to run in its own thread. This would allow for other
plugins and the main application to be free to do other work. I have written a
little TestDriver for the plugin and am having some difficulty.

If I don't use threads everything works just fine. If I do use threads, upon finishing
the thread.Join() loop, I step to the end of main and I receive the same exception 3 times.

Any help would be appreciated.

Dave
DavidElliott@Bellsouth.net

=============================================================

An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.

==============================================================================
[STAThread]
static void Main()
{
IPlugIn plugin = null;
Assembly assembly = null;
Object obj = null;
String s = null;
Thread thr = null;

try
{
assembly = Assembly.LoadFrom("..\\..\\..\\bin\\Debug\\AJB.dll");

Type[] types = assembly.GetExportedTypes( );
foreach (Type t in types )
{
Type interfaceT = t.GetInterface( "IPlugIn" );
if( null != interfaceT )
{
plugin = (IPlugIn)assembly.CreateInstance(t.ToString());

obj = assembly.CreateInstance(t.FullName);
s = obj.GetType().ToString();

plugin.PluginID = 74;

thr = new Thread( new ThreadStart(plugin.Execute) );
thr.ApartmentState = ApartmentState.STA;
thr.IsBackground = false;
thr.Start();
//plugin.Execute();
}
}
}
catch (Exception e)
{
s = Application.ExecutablePath.ToString() + "\n" + e.ToString() + e.Message + e.StackTrace;
MessageBox.Show(s, "ExecutePlugin() Error");
}

thr.Join();
}

Re: Thread Question -=> System.NullReferenceException after exiting main() by David

David
Wed Aug 20 14:50:14 CDT 2003

If I comment out this line:
this.browser = new AxSHDocVw.AxWebBrowser();
from my plugin, then I don't get the exception.

Any thoughts?
Dave

DavidElliott@BellSouth.net


On Tue, 19 Aug 2003 19:59:56 -0400, David Elliott <DavidElliott@BellSouth.net> wrote:

>I have created an application that will dynamically load other DLLs (plugins).
>The new plugin is a winform with an embedded IE Browser.
>
>I am wanting to have the form to run in its own thread. This would allow for other
>plugins and the main application to be free to do other work. I have written a
>little TestDriver for the plugin and am having some difficulty.
>
>If I don't use threads everything works just fine. If I do use threads, upon finishing
>the thread.Join() loop, I step to the end of main and I receive the same exception 3 times.
>
>Any help would be appreciated.
>
>Dave
>DavidElliott@Bellsouth.net
>
>=============================================================
>
>An unhandled exception of type 'System.NullReferenceException'
>occurred in system.windows.forms.dll
>
>Additional information: Object reference not set to an instance of an object.
>
>==============================================================================
>[STAThread]
>static void Main()
>{
> IPlugIn plugin = null;
> Assembly assembly = null;
> Object obj = null;
> String s = null;
> Thread thr = null;
>
> try
> {
> assembly = Assembly.LoadFrom("..\\..\\..\\bin\\Debug\\AJB.dll");
>
> Type[] types = assembly.GetExportedTypes( );
> foreach (Type t in types )
> {
> Type interfaceT = t.GetInterface( "IPlugIn" );
> if( null != interfaceT )
> {
> plugin = (IPlugIn)assembly.CreateInstance(t.ToString());
>
> obj = assembly.CreateInstance(t.FullName);
> s = obj.GetType().ToString();
>
> plugin.PluginID = 74;
>
> thr = new Thread( new ThreadStart(plugin.Execute) );
> thr.ApartmentState = ApartmentState.STA;
> thr.IsBackground = false;
> thr.Start();
> //plugin.Execute();
> }
> }
> }
> catch (Exception e)
> {
> s = Application.ExecutablePath.ToString() + "\n" + e.ToString() + e.Message + e.StackTrace;
> MessageBox.Show(s, "ExecutePlugin() Error");
> }
>
> thr.Join();
>}