By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,223 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,223 IT Pros & Developers. It's quick & easy.

Thread Question -=> System.NullReferenceException after exiting main()

P: n/a
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
Da**********@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();
}

Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
A couple of questions...what is the exception you are getting? Are you
getting the exception when you call Join or after the thread has exited and
you have left the try-catch block and main is about to exit?

I would set the IsBackground to true. Setting it to a false will prevent
your application from exiting until the thread has completetly stopped which
is usually not the type of behavior you will want. In the catch block you
can simply do a e.ToString() to have the exception print both the message
and its stack trace. And I would probably move the thr.Join inside the
try-catch block.

You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may cause
you problems. This path is not in or below the application base directory,
so if the plugin has other assemblies that it depends on the runtime will
not be able to automatically resolve them. You would be better off moving
the plugin to a subdirectory below the application base directory and then
adding the relative path to the subdirectory to the private bin path of the
appdomain. Then you could use Load(xxx) rather then LoadFrom.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:3g********************************@4ax.com...
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
Da**********@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();
}

Nov 15 '05 #2

P: n/a
See comments inline...

Any other thoughts are welcomed.

Thanks,
Dave
Da**********@BellSouth.net

On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:
A couple of questions...what is the exception you are getting? Are you
This is the exception:
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.

getting the exception when you call Join or after the thread has exited and
you have left the try-catch block and main is about to exit?
The join has successfully completed. I step to the last brace } of main and step once
more. So the application is ending.

I would set the IsBackground to true. Setting it to a false will prevent
your application from exiting until the thread has completetly stopped which
is usually not the type of behavior you will want.
Will give this a shot.
In the catch block you
can simply do a e.ToString() to have the exception print both the message
and its stack trace. And I would probably move the thr.Join inside the
try-catch block.

You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may cause
you problems. This path is not in or below the application base directory,
The main application will be set up correctly. I was just trying to create a driver
for the plugin to test.
so if the plugin has other assemblies that it depends on the runtime will
not be able to automatically resolve them. You would be better off moving
the plugin to a subdirectory below the application base directory and then
adding the relative path to the subdirectory to the private bin path of the
appdomain. Then you could use Load(xxx) rather then LoadFrom.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:3g********************************@4ax.com.. .
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
Da**********@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();
}

Nov 15 '05 #3

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

Any thoughts?
Dave

Da**********@BellSouth.net
On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:
A couple of questions...what is the exception you are getting? Are you
getting the exception when you call Join or after the thread has exited and
you have left the try-catch block and main is about to exit?

I would set the IsBackground to true. Setting it to a false will prevent
your application from exiting until the thread has completetly stopped which
is usually not the type of behavior you will want. In the catch block you
can simply do a e.ToString() to have the exception print both the message
and its stack trace. And I would probably move the thr.Join inside the
try-catch block.

You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may cause
you problems. This path is not in or below the application base directory,
so if the plugin has other assemblies that it depends on the runtime will
not be able to automatically resolve them. You would be better off moving
the plugin to a subdirectory below the application base directory and then
adding the relative path to the subdirectory to the private bin path of the
appdomain. Then you could use Load(xxx) rather then LoadFrom.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:3g********************************@4ax.com.. .
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
Da**********@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();
}

Nov 15 '05 #4

P: n/a
Without seeing all the code it's almost impossible to tell what's going on.
One thing to look for is that you may have finalizers running attempting to
access objects that have already been garbage collected. You can have your
plugin call the Dispose method on any objects it have created immediately
before it's thread finishes running.
"David Elliott" <Da**********@BellSouth.net> wrote in message
news:qs********************************@4ax.com...
If I comment out this line:
this.browser = new AxSHDocVw.AxWebBrowser();
from my plugin, then I don't get the exception.

Any thoughts?
Dave

Da**********@BellSouth.net
On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:
A couple of questions...what is the exception you are getting? Are you
getting the exception when you call Join or after the thread has exited andyou have left the try-catch block and main is about to exit?

I would set the IsBackground to true. Setting it to a false will preventyour application from exiting until the thread has completetly stopped whichis usually not the type of behavior you will want. In the catch block you
can simply do a e.ToString() to have the exception print both the message
and its stack trace. And I would probably move the thr.Join inside the
try-catch block.

You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may causeyou problems. This path is not in or below the application base directory,so if the plugin has other assemblies that it depends on the runtime will
not be able to automatically resolve them. You would be better off moving
the plugin to a subdirectory below the application base directory and thenadding the relative path to the subdirectory to the private bin path of theappdomain. Then you could use Load(xxx) rather then LoadFrom.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:3g********************************@4ax.com.. .
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
allowfor 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
sameexception 3 times.

Any help would be appreciated.

Dave
Da**********@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();
}


Nov 15 '05 #5

P: n/a
I have attached a bare minimum, do nothing, uncomplicated project with
source code to demonstrate the problem.

There is a Driver that loads an assembly (WebBrowser.dll) and starts a thread
with a method that is implemented through an interface (Execute).

That method (Execute) performs a ShowDialog for a form (Form1) that contains
an AxWebBrowser. Upon display the AxWebBrowser goes to Google.com.

Click on the close box and watch the exceptions come in.

Thanks for you help.

Dave
On Wed, 20 Aug 2003 21:40:55 -0500, "Dave" <kd******@wi.rr.com> wrote:
Without seeing all the code it's almost impossible to tell what's going on.
One thing to look for is that you may have finalizers running attempting to
access objects that have already been garbage collected. You can have your
plugin call the Dispose method on any objects it have created immediately
before it's thread finishes running.
"David Elliott" <Da**********@BellSouth.net> wrote in message
news:qs********************************@4ax.com.. .
If I comment out this line:
this.browser = new AxSHDocVw.AxWebBrowser();
from my plugin, then I don't get the exception.

Any thoughts?
Dave

Da**********@BellSouth.net
On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:
>A couple of questions...what is the exception you are getting? Are you
>getting the exception when you call Join or after the thread has exitedand >you have left the try-catch block and main is about to exit?
>
> I would set the IsBackground to true. Setting it to a false willprevent >your application from exiting until the thread has completetly stoppedwhich >is usually not the type of behavior you will want. In the catch block you
>can simply do a e.ToString() to have the exception print both the message
>and its stack trace. And I would probably move the thr.Join inside the
>try-catch block.
>
>You should also be aware that using LoadFrom("..\\..\\..\\.. etc") maycause >you problems. This path is not in or below the application basedirectory, >so if the plugin has other assemblies that it depends on the runtime will
>not be able to automatically resolve them. You would be better off moving
>the plugin to a subdirectory below the application base directory andthen >adding the relative path to the subdirectory to the private bin path ofthe >appdomain. Then you could use Load(xxx) rather then LoadFrom.
>
>"David Elliott" <Da**********@BellSouth.net> wrote in message
>news:3g********************************@4ax.com.. .
>> 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 wouldallow >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 usethreads, >upon finishing
>> the thread.Join() loop, I step to the end of main and I receive thesame >exception 3 times.
>>
>> Any help would be appreciated.
>>
>> Dave
>> Da**********@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();
>> }
>>
>


Nov 15 '05 #6

P: n/a
All that came through was gibberish - did you attach a file to the email?

Doing UI in a worker thread is risky - unless you have a message pump
somewhere delivering window events things will not work properly. If the
dialog form has a dispose method you should call it. You can also call
GC.WaitForPendingFinalizers to ensure that it has cleaned itself up before
letting the thread terminate.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:sv********************************@4ax.com...
I have attached a bare minimum, do nothing, uncomplicated project with
source code to demonstrate the problem.

There is a Driver that loads an assembly (WebBrowser.dll) and starts a thread with a method that is implemented through an interface (Execute).

That method (Execute) performs a ShowDialog for a form (Form1) that contains an AxWebBrowser. Upon display the AxWebBrowser goes to Google.com.

Click on the close box and watch the exceptions come in.

Thanks for you help.

Dave
On Wed, 20 Aug 2003 21:40:55 -0500, "Dave" <kd******@wi.rr.com> wrote:
Without seeing all the code it's almost impossible to tell what's going on.One thing to look for is that you may have finalizers running attempting toaccess objects that have already been garbage collected. You can have yourplugin call the Dispose method on any objects it have created immediately
before it's thread finishes running.
"David Elliott" <Da**********@BellSouth.net> wrote in message
news:qs********************************@4ax.com.. .
If I comment out this line:
this.browser = new AxSHDocVw.AxWebBrowser();
from my plugin, then I don't get the exception.

Any thoughts?
Dave

Da**********@BellSouth.net
On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:

>A couple of questions...what is the exception you are getting? Are you
>getting the exception when you call Join or after the thread has exited
and
>you have left the try-catch block and main is about to exit?
>
> I would set the IsBackground to true. Setting it to a false will

prevent
>your application from exiting until the thread has completetly stopped

which
>is usually not the type of behavior you will want. In the catch block
you >can simply do a e.ToString() to have the exception print both the message >and its stack trace. And I would probably move the thr.Join inside the
>try-catch block.
>
>You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may

cause
>you problems. This path is not in or below the application base

directory,
>so if the plugin has other assemblies that it depends on the runtime will >not be able to automatically resolve them. You would be better off moving >the plugin to a subdirectory below the application base directory and

then
>adding the relative path to the subdirectory to the private bin path ofthe
>appdomain. Then you could use Load(xxx) rather then LoadFrom.
>
>"David Elliott" <Da**********@BellSouth.net> wrote in message
>news:3g********************************@4ax.com.. .
>> 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
>> Da**********@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();
>> }
>>
>


Nov 15 '05 #7

P: n/a
Between the thread and using ShowDialog(), I should have a message pump.
This is one of the reasons that I was doing it this way. This would allow the main
application to start other plugins as well as continue with its own thing.

I added the generic Dispose() that was inherited (ie I didn't implement IDisposable)
as you suggested and this took care of the problem.

I don't really understand why just instantiating a class of type AxSHDocVw.AxWebBrowser
would create the exceptions. I will have to see if I can find an answer.

Thanks for your time, patience and solution.

Cheers,
Dave

On Thu, 21 Aug 2003 05:48:26 -0500, "Dave" <kd******@wi.rr.com> wrote:
All that came through was gibberish - did you attach a file to the email?

Doing UI in a worker thread is risky - unless you have a message pump
somewhere delivering window events things will not work properly. If the
dialog form has a dispose method you should call it. You can also call
GC.WaitForPendingFinalizers to ensure that it has cleaned itself up before
letting the thread terminate.

"David Elliott" <Da**********@BellSouth.net> wrote in message
news:sv********************************@4ax.com.. .
I have attached a bare minimum, do nothing, uncomplicated project with
source code to demonstrate the problem.

There is a Driver that loads an assembly (WebBrowser.dll) and starts a

thread
with a method that is implemented through an interface (Execute).

That method (Execute) performs a ShowDialog for a form (Form1) that

contains
an AxWebBrowser. Upon display the AxWebBrowser goes to Google.com.

Click on the close box and watch the exceptions come in.

Thanks for you help.

Dave
On Wed, 20 Aug 2003 21:40:55 -0500, "Dave" <kd******@wi.rr.com> wrote:
>Without seeing all the code it's almost impossible to tell what's goingon. >One thing to look for is that you may have finalizers running attemptingto >access objects that have already been garbage collected. You can haveyour >plugin call the Dispose method on any objects it have created immediately
>before it's thread finishes running.
>
>
>"David Elliott" <Da**********@BellSouth.net> wrote in message
>news:qs********************************@4ax.com.. .
>> If I comment out this line:
>> this.browser = new AxSHDocVw.AxWebBrowser();
>> from my plugin, then I don't get the exception.
>>
>> Any thoughts?
>> Dave
>>
>> Da**********@BellSouth.net
>>
>>
>> On Wed, 20 Aug 2003 05:13:28 -0500, "Dave" <kd******@wi.rr.com> wrote:
>>
>> >A couple of questions...what is the exception you are getting? Are you
>> >getting the exception when you call Join or after the thread hasexited >and
>> >you have left the try-catch block and main is about to exit?
>> >
>> > I would set the IsBackground to true. Setting it to a false will
>prevent
>> >your application from exiting until the thread has completetly stopped
>which
>> >is usually not the type of behavior you will want. In the catch blockyou >> >can simply do a e.ToString() to have the exception print both themessage >> >and its stack trace. And I would probably move the thr.Join inside the
>> >try-catch block.
>> >
>> >You should also be aware that using LoadFrom("..\\..\\..\\.. etc") may
>cause
>> >you problems. This path is not in or below the application base
>directory,
>> >so if the plugin has other assemblies that it depends on the runtimewill >> >not be able to automatically resolve them. You would be better offmoving >> >the plugin to a subdirectory below the application base directory and
>then
>> >adding the relative path to the subdirectory to the private bin pathof >the
>> >appdomain. Then you could use Load(xxx) rather then LoadFrom.
>> >
>> >"David Elliott" <Da**********@BellSouth.net> wrote in message
>> >news:3g********************************@4ax.com.. .
>> >> 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. Ihave >> >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
>> >> Da**********@Bellsouth.net
>> >>
>> >> ================================================== ===========
>> >>
>> >> An unhandled exception of type 'System.NullReferenceException'
>> >> occurred in system.windows.forms.dll
>> >>
>> >> Additional information: Object reference not set to an instance ofan >> >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();
>> >> }
>> >>
>> >
>>
>>
>


Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.