Invoke Method

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi

I have a second thread running and I want to invoke a method in a class on
the 1st thread, how can I do this without using a form?

Thanks
Kev
 
I have an asp net app and there is a continuously running thread that
services aspx page responses, but the class that actually kicks off these
pages will run in the first thread, I want to run methods on this class from
the thread in which the class was instantiated, so that I can access the
HttpContext.Current object.

HTMS
Kev
 
Hi...

You need some form of inter-thread communication. The architectural manner
in which this is done is via ISynchronizer. You can take advantage of a
system-provided implementation via using a delegate. In other words, from
the 2nd thread, create a delegate that wraps a call to the object/method in
the 1st thread. Then, call Invoke on the delegate. The system will shuttle
the call from the caller to the callee.

John Puopolo
 
No, this requires a Form and a message pump and that's not what OP was
looking for.

Willy.
 
Mantorok said:
I have an asp net app and there is a continuously running thread that
services aspx page responses, but the class that actually kicks off these
pages will run in the first thread, I want to run methods on this class
from the thread in which the class was instantiated, so that I can access
the object.

HTMS
Kev

But, if you call a method on that class you have access to
HttpContext.Current, no matter what thread you are executing this method on,
right?
Sure it's possible you need to synchronize access to the object, but here
you can use .NET's provided synchronizing primitives.

Willy.
 
But, if you call a method on that class you have access to
HttpContext.Current, no matter what thread you are executing this method on,
right?

No - the value of HttpContext.Current depends on the calling thread. It
has to, as it's a static property - it couldn't possibly know which
context you're talking about unless it were thread-sensitive.
 
Jon Skeet said:
No - the value of HttpContext.Current depends on the calling thread. It
has to, as it's a static property - it couldn't possibly know which
context you're talking about unless it were thread-sensitive.

Sure you are right, the Context can only be accessed from the thread
executing the request.
So the only option is to make the context object explicitly available to the
thread executing outside the HttpRequest pipeline.

Willy.
 
Willy Denoyette said:
Sure you are right, the Context can only be accessed from the thread
executing the request.
So the only option is to make the context object explicitly available to
the thread executing outside the HttpRequest pipeline.

Which begs the question, is that possible?

Kev
 
Mantorok said:
Which begs the question, is that possible?

Well, I suspect you could pass the context as parameter, or make it
available to another thread in the way that you make other data
available.
 
Back
Top