我有两个控制台应用程序:
以下代码演示了我如何初始化SignalR服务器:
public void Configuration(IAppBuilder app)
{
HttpConfiguration webApiConfiguration = ConfigureWebApi();
app.UseWebApi(webApiConfiguration);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.MapSignalR(new HubConfiguration() { EnableDetailedErrors = true });
}
Run Code Online (Sandbox Code Playgroud)
这就是我试图从客户端应用程序建立与服务器的连接:
public void Run()
{
HubConnection hubConnection = new HubConnection(this.hubConnectionURL);
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
remoteServerHubProxy = hubConnection.CreateHubProxy("SignalRHub");
remoteServerHubProxy.On<Int32, MyModel>("MethodName", new Action<Int32, MyModel>((lid, model) => this.MethodName(lid, model)));
hubConnection.Start().Wait();
}
Run Code Online (Sandbox Code Playgroud)
每当Start().Wait()执行时,以下异常发生在客户端:
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at …Run Code Online (Sandbox Code Playgroud) 我有一个包含Button和RichTextBox控件的WinForms应用程序.用户单击Button后,将执行IO要求操作.为了防止阻塞UI线程,我实现了async/await模式.我还想将此操作的进度报告给RichTextBox.这就是简化逻辑的样子:
private async void LoadData_Click(Object sender, EventArgs e)
{
this.LoadDataBtn.Enabled = false;
IProgress<String> progressHandler = new Progress<String>(p => this.Log(p));
this.Log("Initiating work...");
List<Int32> result = await this.HeavyIO(new List<Int32> { 1, 2, 3 }, progressHandler);
this.Log("Done!");
this.LoadDataBtn.Enabled = true;
}
private async Task<List<Int32>> HeavyIO(List<Int32> ids, IProgress<String> progress)
{
List<Int32> result = new List<Int32>();
foreach (Int32 id in ids)
{
progress?.Report("Downloading data for " + id);
await Task.Delay(500); // Assume that data is downloaded from the web here.
progress?.Report("Data loaded successfully for " …Run Code Online (Sandbox Code Playgroud) 这个问题是在ASP.NET WebApi 2(不是 ASP.NET Core)的上下文中提出的。我试图对这个主题进行自己的研究,但是我找不到明确的答案。
官方的MSDN文档的ConfigureAwait(...)方法的参数规定如下:
true尝试将延续编组回捕获的原始上下文;否则,false。
Stephen Toub进一步解释该attempt关键字如下:
这意味着可能没有任何东西可以编组回......可能没有要捕获的上下文,例如
SynchronizationContext.Current可能返回null。
如果我理解正确,那么 ASP.NET WebApi 2 就不是这种情况,因为AspNetSynchronizationContext存在,对吗?
现在让我们看看以下控制器操作方法:
[HttpGet]
public async Task<String> GetValues()
{
// First half.
var values = await HeavyIo().ConfigureAwait(false);
// Second half.
return values;
}
Run Code Online (Sandbox Code Playgroud)
通过将continueOnCapturedContext: false能够保证所有的是,标为继续// Second half.得到总是在不同的线程中执行?或者,如果异步操作完成时捕获同步上下文的线程将空闲,那么延续将在同一个线程上运行?
我们已经在我们的企业团队中启用了 Bot Framework 应用程序,我们希望使用它AdaptiveCards向用户呈现丰富的内容。例如,我们发送AdaptiveImage包含指向企业形象商店的 url。
示例代码:
new AdaptiveImage
{
Size = AdaptiveImageSize.Small,
Url = new Uri("https://corporate-storage.com/images/image1.png"), // This is image not hosted publicly.
AltText = "Some text"
}
Run Code Online (Sandbox Code Playgroud)
这在 WebChat 客户端中工作得很好,因为 url 只是附加到HTML 标记src的属性中img。然而,在 MS Teams 中,它似乎是由一些奇怪的代理/MITM 进行预处理的,并且 url 结果如下:
https://urlp.asm.skype.com/v1/url/content?url=https%3a%2f%2fcorporate-proxy.com%2fimages%2fimage1.png
当我们尝试浏览 url 以查看图片未渲染的原因时,我们在调试器中看到带有 502 响应代码的空白页面。
有没有办法强制 MS Teams 不更改src图片属性。
c# ×3
asp.net ×2
async-await ×2
.net ×1
asynchronous ×1
botframework ×1
signalr ×1
winforms ×1