473,416 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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
7 3963
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
3
by: Paul Bowman | last post by:
Hi All Does anybody have any ideas what I am doing wrong with this code. What I am trying to do is read data from a Domino Database. For purposes of the test I have wrapped the DominoCom...
7
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at...
7
by: Ram | last post by:
Hi, I have two threads, one parent thread containing UI and a child thread waiting for some events from the parent thread. Now, I have two issues: 1) to keep the child thread active till the end...
5
by: [Yosi] | last post by:
Why I can't abot a susspended thread. Who can terminat a thread imediatly without consider to its stat or execution?
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
22
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
6
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.