Delegate and Thread Problem

I

Irfan

I have a Delegate based Project that contain classes whose purpose is to
instantiate objects of another Project (or Library) using Delegates. I have
a client application that uses this Delegate based project to call library
method asynchronously. Delegate based project returns the control to the
client immediately and so the client can perorm other tasks. Every thing
works fine but soon as i close the client application, the back ground
processing also ends. In other words, the Delegate based project and library
Project also stops. why is that? How can i call method using delegate that
continue the processing even if the client application terminates.

I can work around this scenario by creating threads and calling method in
thread. My client application calls the method of a project named
ThreadCreator. The ThreadCreator in turn creates a new thread and calls the
appropriate library method in that thread. Now even if the client
application terminates, my processing continues. The problem with this
approach is that my ThreadCreator project cant call method that takes
parameters. The work aournd here is to go for statefull object, but my
library objects are all stateless. How can i call method using thread that
takes parameters ?

Please answer for both scenario


Regards,
Irfan
 
N

Nick Harris

[See Below]

Irfan said:
I have a Delegate based Project that contain classes whose purpose is to
instantiate objects of another Project (or Library) using Delegates. I have
a client application that uses this Delegate based project to call library
method asynchronously. Delegate based project returns the control to the
client immediately and so the client can perorm other tasks. Every thing
works fine but soon as i close the client application, the back ground
processing also ends. In other words, the Delegate based project and library
Project also stops. why is that? How can i call method using delegate that
continue the processing even if the client application terminates.

[My guess would be that any threads created via events from the UI thread
would be controlled by the UI thread.
If you have a delegate in your app that's made (or makes) a call and that
delegate looses scope (b/c the app terminated) anything it's attached to
would also terminate. So basically you create a new thread in your local
app that is actually doing the work. If you make an async thread call using
BeginInvoke, you shouldn't have this problem]

I can work around this scenario by creating threads and calling method in
thread. My client application calls the method of a project named
ThreadCreator. The ThreadCreator in turn creates a new thread and calls the
appropriate library method in that thread. Now even if the client
application terminates, my processing continues. The problem with this
approach is that my ThreadCreator project cant call method that takes
parameters. The work aournd here is to go for statefull object, but my
library objects are all stateless. How can i call method using thread that
takes parameters ?

[Umm...if i understand you correctly, I would simply use the object instance
to my advantage:

MyObject o = new MyObject();
o.SetParameters(x,y,z);

Thread t = new Thread(new ThreadStart(o.RunReport));

or something to that effect.
]



HTH,

Nick Harris, MCSD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top