相关疑难解决方法(0)

你能解释一下STA和MTA吗?

你能用自己的话解释STA和MTA吗?

什么是公寓线程,它们只与COM有关吗?如果是这样,为什么?

.net com multithreading apartments

385
推荐指数
7
解决办法
13万
查看次数

AspNetSynchronizationContext

试图使用新的C#5异步模型,令我惊讶的AspNetSynchronizationContext是内部类(以及AspNetSynchronizationContextBase基础).因而无证.但是,在ASP.NET代码中使用async/await功能时,了解它的作用至关重要.我是否正确,它确实保证您的延续将与HttpContext.Current原始呼叫者相同?它保证continuation将在与调用者相同的线程上执行吗?

如果后一个假设不正确并且我得到原始线程,我可以确保在continuation中获得相同的线程上下文吗?我的意思是与线程和线程本地存储相关的主体/文化?这很重要,因为ASP.NET本地化依赖于线程的文化,而我的应用程序依赖于.NET角色安全模型(线程的主体).

.net asp.net asynchronous async-await c#-5.0

22
推荐指数
2
解决办法
4253
查看次数

'等待'任务在哪里执行?

考虑以下:

private async void btnSlowPoke_Click(object sender, EventArgs e)
{
    await DoItAsync();
}

private async Task<int> SomeLongJobAsync()
{
    for (int x = 0; x < 999999; x++)
    {
        //ponder my existence for one second
        await Task.Delay(1000);
    }
    return 42;
}

public async Task<int> DoItAsync()
{
    Console.Write("She'll be coming round the mountain");
    Task<int> t = SomeLongJobAsync();  //<--On what thread does this execute?
    Console.WriteLine(" when she comes.");
    return await t;
}
Run Code Online (Sandbox Code Playgroud)
  1. 第一个写入DoItAsync()执行.
  2. SomeLongJobAsync() 开始.
  3. WriteLineDoItAsync()执行.
  4. DoItAsync()在 …

c# multithreading asynchronous task-parallel-library async-await

6
推荐指数
1
解决办法
287
查看次数