Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question regarding appropriate use for Task in C#

Tags:

c#

wcf

I have a question regarding Task. I have a WCF app which has a method ReceiveEmpInfo which will be called from a client app.

WCF Server app:

public void ReceiveEmpInfo(string EmpName, string EmpId)
{
    DifferentClass.SaveEmpToDB(string EmpName, string EmpId);
    return;
}

My requirement is I want to return this method call (ReceiveEmpInfo()) once I call the method SaveEmpToDB(), I don’t want to hold the client call until the SaveEmpToDB() method saves the data to the database. I’m thinking of using Task, but I’m not sure whether it will solve my requirement.

Please give me your suggestions.

Thanks, Joe

like image 472
Joboy Avatar asked Feb 19 '26 11:02

Joboy


1 Answers

Yes, it will. Once you call Task.Start() your WCF method can return and the task will run in the "background". You have to be very careful, especially if you're running this WCF service inside of IIS. If these tasks are very long running and the IIS application pool shuts down (or gets restarted) your task is going to get whacked [potentially] in the middle of its work.

BTW: I'm assuming you're referring to: System.Threading.Tasks.Task

like image 151
CodingGorilla Avatar answered Feb 21 '26 15:02

CodingGorilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!