Skip to content

New generic TaskFactory.StartNew<T> API #19498

@djechelon

Description

@djechelon

Hi,

I would like to suggest to add an additional overload to TaskFactory

To the existing

 StartNew(Action<Object>, Object, CancellationToken, TaskCreationOptions, TaskScheduler)

I would add

 StartNew(Action<T>, T, CancellationToken, TaskCreationOptions, TaskScheduler)

The reason is not to force the developer to do runtime checks and casts when the invoked method accepts an object (or a collection) of type T which is well-known at compile time

Current code:

 private void Insert(Object state)
        {
            var entities = state as IEnumerable<Entity>;
            using (var context = GetDataContext())
            {
                context.entities.AddRange(entities);
                context.SaveChanges();
            }
        }

Task.Factory.StartNew(Insert, entityList); //invoked with

Desiderata:

 private void Insert(IEnumerable<Entity> entities)
        {
            using (var context = GetDataContext())
            {
                context.entities.AddRange(entities);
                context.SaveChanges();
            }
        }

Task.Factory.StartNew(Insert, entityList); //invoked with

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workAPI needs work before it is approved, it is NOT ready for implementationarea-System.Threading

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions