Yes, but only by calling it:
Func<object> func = delegate { return a; };
object b = func();
And, of course, the following is much simpler ...
object b = a;
The comments mention cross-thread exceptions; this can be fixed as follows:
If the delegate is what we want to run in the user interface thread from the BG stream:
object o = null;
MethodInvoker mi = delegate {
o = someControl.Value;
};
someControl.Invoke(mi);
Or vice versa (to run a delegate in BG):
object value = someControl.Value;
ThreadPool.QueueUserWorkItem(delegate {
});
source
share