Is task-based programming acceptable on an ASP.Net or Async page - preferred approach

I am using the following task-based programming (TPL) on a page that is not an Async page.

My question is: Is it possible to use TPL (for example, a parallel task library) to create multi-threaded calls on an ASP.Net page, or should I always use the built-in Async function for multithreading in an ASP.Net page? Until now, the TPL approach has not created any problems, but just wanted to be sure that I missed some important problems / hidden risks using TPL on the ASP.Net page.

       Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Method1(); 
                        success4 = true;
                    }
                    catch (Exception e4)
                    {
                        success4 = false;
                        ex = e4.ToString();
                    }
                }),
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Method2();
                        success5 = true;
                    }
                    catch (Exception e5)
                    {
                        success5 = false;
                        ex = e5.ToString();
                    }
                }),
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Method3();
                        success6 = true;
                    }
                    catch (Exception e6)
                    {
                        success6 = false;
                        ex = e6.ToString();
                    }
                })
            };
   Task.WaitAll(tasks);

UPDATE 1:

, TPL ASP.Net ASP.Net, ASP.Net .
TPL Async, , , parallelism. , , TPL .

private void DoTask4(object[] paras)
    {
        Parallel.Invoke(() =>
            {
               try
               {
                   Method4( paras);
               }
               catch (Exception e4)
               {
                   success4 = false;
                   //log the exception
               }
           });
    }

    IAsyncResult BeginAsyncOperation4(object sender, EventArgs e, AsyncCallback cb, object state)
    {
        task4 = new AsyncTaskDelegate(DoTask4);
        IAsyncResult result = task4.BeginInvoke(state as object[], cb, "task4");
        return result;
    }

    void EndAsyncOperation4(IAsyncResult ar)
    {
        task4.EndInvoke(ar);
        if (success4 == null)
        {
            success4 = true;
        }
    }

    void TimeoutAsyncOperation4(IAsyncResult ar)
    {
        success4 = false;
    }

2:

, , TPL Async , , , ASP.Net . TPL Async.

+4
1

, . , Method1..3 , IO. async ASP.NET-, async IO- AsyncManager (, this) PageAsyncTask ( ASP.NET) .

( IO), , , . Task.Factory.StartNew HTTP- , . , , HTTP-, .

, - HTTP-. , .

+2

Source: https://habr.com/ru/post/1536902/


All Articles