In async programming, there are 3 different models for different scenarios :
- Asynchronous Programming Model – APM
- Task Based Asynchronous Programming Model – TAPM
- Evented Asynchronous Programming Model – EAPM
We can use all models in .net framework. It provides related libraries in their own namespaces. The Task-based Asynchronous Pattern (TAP) is based on System.Threading.Tasks.Task and System.Threading.Tasks.Task<TResult> types in the System.Threading.Tasks namespaces.
When we’re developing web application, if we need to develop async applications on web side, we can use this libraries to reflect async behavior. For Instance, if we want to communicate external services or channels at the same time, we might use async controller to avoid operation blocks. When we’re reflecting this behavior in an application, We should think tasks in action level. I mean, surely according to our scenario, if we seperate all actions as different tasks, it can be more useful and manageble.
In .Net Framework MVC Applications, We can use Async Controllers and async actions. For instance please check code below :
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
AsyncController
{
}
)
{
;
}
)
{
;
;
;
;
;
;
;
;
;
}
)
{
)
{
,
)
;
;
}
)
{
)
{
,
)
;
;
}
)
{
;
;
;
;
;
;
;
}
}
IndexViewModel
{
}
}
}
}
}
|
And also, if you need to run multiple requests concurrently, use SessionLess controller :
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
]
Controller
{
}
)
{
;
}
)
{
;
;
;
;
;
;
;
;
;
}
)
{
)
{
,
)
;
;
}
)
{
)
{
,
)
;
;
}
)
{
;
;
;
;
;
;
;
}
}
IndexViewModel
{
}
}
}
}
}
|
AST
This entry was posted in .Net Framework, ASP.Net, Design Patterns, MVC, Server Side Web Programming,Web Programming and tagged async, asynchronous operations, controller, mvc 5, sessionless, tap, task based asynchronous pattern on July 4, 2016.