G
gs_sarge
Hi:
I have a couple of questions about threads and asynchronous calls
Question 1: How are these two different?
Situation a:
Caller calls method1 with parameters
Method1 takes parameters from caller,
creates an object with those parameters
passed in to be stored by the object as member variable,
calls a thread method on the object,
starts thread and returns.
Situation b:
Caller calls method2 with parameter
Method2 takes parameters from caller,
creates async delegate for a method in its class,
calls asynchronously the method, giving it a
callback function with the delegate as the last argument
and returns.
when the async call is complete, it calls the callback function
which takes the delegate object passed to it and endinvokes it.
Question 2:
If two different delegate wrappers for the same method are called back
to back, will they run concurrently on the system, or does the second
method call have to wait for the first one to finish before executing.
Of course for this I would pass in a callback function that would
handle the endinvoke. In that way, at least from the outside, it
would look like they behaved like threads. But what about internally.
Would they truly behave like threads?
For my situation, if they behaved exactly like threads, it would be
very beneficial to me. I find greater flexibility with asynchronous
calls because I can pass in parameters. Of course, if I created
objects to do my work in a thread, I could give it parameters to hold
as member variables, but that would require creating an additional
object. But if I wanted to use a class method to do the work, using a
thread would prevent me from passing in parameters. With async calls,
I can pass in a reference parameter, which could be modified by the
async call. I could then check the state of the reference parameter.
In this sense, I can pass in parameters and get return values (could
also just use an out variable).
Question 3:
If a delegate is passed to a function as a ref parameter, and it has a
method that can be threaded, can that method be threaded by the
function and let to do it's work. And if so, if thread modified its
object's state information, would those changes be seen by the
original object passed?
If both caller and function are in the app domain, it really isn't
that important to me? But what if they are in different domains? For
example, what if the caller is using a remote object, and passing in a
delegate object that will be threaded on the remote machine. In which
domain is the thread running?
Answers to these questions will be greatly appreciated and will help
me in my understanding of multi-threading in C# and .NET
Steve
I have a couple of questions about threads and asynchronous calls
Question 1: How are these two different?
Situation a:
Caller calls method1 with parameters
Method1 takes parameters from caller,
creates an object with those parameters
passed in to be stored by the object as member variable,
calls a thread method on the object,
starts thread and returns.
Situation b:
Caller calls method2 with parameter
Method2 takes parameters from caller,
creates async delegate for a method in its class,
calls asynchronously the method, giving it a
callback function with the delegate as the last argument
and returns.
when the async call is complete, it calls the callback function
which takes the delegate object passed to it and endinvokes it.
Question 2:
If two different delegate wrappers for the same method are called back
to back, will they run concurrently on the system, or does the second
method call have to wait for the first one to finish before executing.
Of course for this I would pass in a callback function that would
handle the endinvoke. In that way, at least from the outside, it
would look like they behaved like threads. But what about internally.
Would they truly behave like threads?
For my situation, if they behaved exactly like threads, it would be
very beneficial to me. I find greater flexibility with asynchronous
calls because I can pass in parameters. Of course, if I created
objects to do my work in a thread, I could give it parameters to hold
as member variables, but that would require creating an additional
object. But if I wanted to use a class method to do the work, using a
thread would prevent me from passing in parameters. With async calls,
I can pass in a reference parameter, which could be modified by the
async call. I could then check the state of the reference parameter.
In this sense, I can pass in parameters and get return values (could
also just use an out variable).
Question 3:
If a delegate is passed to a function as a ref parameter, and it has a
method that can be threaded, can that method be threaded by the
function and let to do it's work. And if so, if thread modified its
object's state information, would those changes be seen by the
original object passed?
If both caller and function are in the app domain, it really isn't
that important to me? But what if they are in different domains? For
example, what if the caller is using a remote object, and passing in a
delegate object that will be threaded on the remote machine. In which
domain is the thread running?
Answers to these questions will be greatly appreciated and will help
me in my understanding of multi-threading in C# and .NET
Steve