Parameterless void delegate?

  • Thread starter Thread starter Shak
  • Start date Start date
S

Shak

Hi,

Does the Framework provide a standard void, parameterless delegate?
Something like ThreadStart but without the implication that it will be used
to start a thread?

Shak
 
You can roll your own. Why would you need for the Framework to provide that?

It's a simply one liner but many applications need it sooner or later
so it would nice to have a common type so that future merging of code
doesn't create overlaps. I don't know why they couldn't have just
called the ThreadStart delegate VoidFunction and then everyone would
be happy.
 
Israel said:
It's a simply one liner but many applications need it sooner or later
so it would nice to have a common type so that future merging of code
doesn't create overlaps. I don't know why they couldn't have just
called the ThreadStart delegate VoidFunction and then everyone would
be happy.

I have to say I've wished for this too - Action<T> is nice and general,
but when you don't need any parameters, it's a bit silly...
 
It is a real shame that MethodInvoker was placed in
System.Windows.Forms and not System.ComponentModel (and System.dll).
Although I guess any utility dll could donate such...

I guess since it is only a name ThreadStart should suffice, but then
you confuse people into thinking that threading is involved, when it
is just a callback (or similar). I don't see much benefit in declaring
another void() delegate just to clarify this, but I do get sick of
adding the comment:
// just a callback - no threading here...
ThreadStart callback = SomeMethod;

Marc
 
Jon Skeet said:
I have to say I've wished for this too - Action<T> is nice and general,
but when you don't need any parameters, it's a bit silly...

And it's in System, which is cool. But then even Action<T> brings baggage
with it. Well, if you read the docs it does anyway.

Shak
 
Shak said:
And it's in System, which is cool. But then even Action<T> brings baggage
with it. Well, if you read the docs it does anyway.

I've just looked at the docs and I don't understand what baggage you're
talking about - could you elaborate?
 
Jon Skeet said:
I've just looked at the docs and I don't understand what baggage you're
talking about - could you elaborate?

It seems to have been specifically created for the ForEach method on
collections etc. This doesn't affect its use of course, but then it could
lead people reading my code down the wrong path anyway; you may as well just
use ThreadStart instead.

Shak
 
Shak said:
It seems to have been specifically created for the ForEach method on
collections etc.

Well, those are the obvious *examples* - but I don't think that really
counts as "baggage".
This doesn't affect its use of course, but then it could lead people
reading my code down the wrong path anyway; you may as well just use
ThreadStart instead.

Well, you can't use ThreadStart if there are parameters and you can't
use Action if there aren't, but that aside - an Action<T> is just meant
to perform an action based on a single parameter. There's nothing that
ties it to collections, otherwise it would be in the
System.Collections.Generic namespace. I agree that the documentation
could be a bit clearer in that respect, but I don't think there's
nearly the same implicit tie between Action<T> and collections as there
is between ThreadStart and starting a thread.
 
Back
Top