Search code examples
c#.netasynchronous-method-call

How to call a method asynchronously in c#


I have a method public void foo(){} which in turn calls another method public void fooBL(){} which is in the BusinessLogic layer. fooBL() then calls another method fooDAL() which is in the DataAccessLayer. I want to call foo() asynchronously on a button click event. I'm using .NET4.0.


Solution

  • It depends on what your goal is.

    The simplest way to call foo asynchronous is:

    Task t = new Task.Factory.StartNew(foo);