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 9 1577
Why would you ever need to do this?
Willy.
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cu**********@newsfeed.th.ifl.net... 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
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OL*************@TK2MSFTNGP15.phx.gbl... Why would you ever need to do this?
Willy.
"Mantorok" <no**@tiscali.co.uk> wrote in message news:cu**********@newsfeed.th.ifl.net... 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
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cu**********@newsfeed.th.ifl.net... 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
No, this requires a Form and a message pump and that's not what OP was
looking for.
Willy.
"John Puopolo" <jo**********@fastsearch.com.nospam> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl... 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
"Mantorok" <no**@tiscali.co.uk> wrote in message news:cu**********@newsfeed.th.ifl.net... 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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cu**********@newsfeed.th.ifl.net... 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.
Willy Denoyette [MVP] <wi*************@pandora.be> wrote: 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.
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 - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Willy Denoyette [MVP] <wi*************@pandora.be> wrote: >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.
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 - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
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 [MVP]" <wi*************@pandora.be> wrote in message
news:uN****************@TK2MSFTNGP12.phx.gbl... "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Willy Denoyette [MVP] <wi*************@pandora.be> wrote: >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.
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 - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
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 <no**@tiscali.co.uk> wrote: 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?
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.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: boxim |
last post by:
hi all,
I'm having a few problems whereby my application is hanging when using the
Invoke method of a form's control.
Basically, when a user clicks a button on the form, it calls a remote...
|
by: Tom |
last post by:
Hi Everybod
I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate...
|
by: Alex Zhitlenok |
last post by:
Hi,
On Google, one can find a lot of statements that Invoke and
InvokeMemeber work alike. However, my own experience contradicts this
statement.
1. Surprisingly, Invoke and InvokeMember methods...
|
by: RickDee |
last post by:
Please help, anybody.
I am trying to write a program so that it can launch an exe file ( which is
also genereated in C# ) and then simulate the button clicking and invoke the
methods inside the...
|
by: Simon King |
last post by:
I have created a service which uses the FileSystemWatcher to monitor folders
for file changes. I have a app.config file which specifies which folders to
watch and what to do when a change occurs.
...
|
by: Manfred Braun |
last post by:
Hi All,
I am able to invoke some methods from an instance of a loaded assembly, but
I am not able to invoke the loaded assemblie's "Main" method. I try it this
way:
Assembly assembly =...
|
by: stic |
last post by:
Hi,
I'm in a middle of writing something like 'exception handler wraper'
for a set of different methodes.
The case is that I have ca. 40 methods form web servicem, with
different return values...
|
by: stephan querengaesser |
last post by:
hi ng,
i try to invoke a webservice-method with an filter-object, that
contains value types. if i don´t want to filter the return value of
the method, i have to pass a new instance of the...
|
by: Dom |
last post by:
I'm teaching myself about delegates and the Invoke method, and I have
a few newbie questions for the gurus out there:
Here are some CSharp statements:
1. public delegate void MyDelegate (int k,...
|
by: balabaster |
last post by:
I have a class that I want to make thread-safe and am investigating the ISyncronizeInvoke interface and wondering just what it will take to implement this interface. So far the basic concept of my...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |