Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameter in Task

I have a function GetPivotedDataTable(data, "date", "id", "flag") is returning data in Pivoted format. I want to call this method using Task but how to pass multiple parameter in Task.

like image 489
J R B Avatar asked Aug 03 '13 06:08

J R B


People also ask

How do you pass multiple parameters to a function?

The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.

Can you have multiple parameters?

Note that when you are working with multiple parameters, the function call must have the same number of arguments as there are parameters, and the arguments must be passed in the same order.

Can a method accept multiple parameters?

Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.

How do you add multiple arguments in python?

In Python, by adding * and ** (one or two asterisks) to the head of parameter names in the function definition, you can specify an arbitrary number of arguments (variable-length arguments) when calling the function.


1 Answers

You could use lambda expression, or a Func to pass parameters:)

public Form1()
{
    InitializeComponent();

    Task task = new Task(() => this.GetPivotedDataTable("x",DateTime.UtcNow,1,"test"));
    task.Start();
}

public void GetPivotedDataTable(string data, DateTime date, int id, string flag)
{
    // Do stuff
}
like image 122
Martijn van Put Avatar answered Oct 03 '22 05:10

Martijn van Put