小编Chr*_*ett的帖子

HttpClient 上的连接和响应的单独超时

HttpClient调用超时/取消的方法有多种:通过设置HttpClient.Timeout属性、传入 a CancellationToken、使用自定义HttpMessageHandler等。所有这些方法的问题是,无论服务器是否满足超时要求,调用都会被取消根本无法联系到或者只是需要更长的时间才能回复。

我想要实现的行为的一个现有示例是 Postman:
当(对于此示例)我的 ASP.NET Core Web API 当前未运行并且我通过 Postman 发送请求时,它会在 5 秒左右后立即停止。但是当我的 Web API 运行时,我通过 Postman 发送请求,然后在代码中命中断点或添加延迟或其他内容,然后 Postman 将等待其设置中指定的毫秒数(= 超过 5 秒)。

这就是我想要的工作。我的 HTTP 请求有两个不同的超时。一种用于等待与服务器的连接,另一种用于等待其响应。如果在等待响应期间与服务器的连接中断时呼叫也会被取消,那就完美了。在 C# 中(使用 .NET 6)是否可以实现类似的功能?如果可以,如何实现?

.net c# http .net-core .net-6.0

9
推荐指数
2
解决办法
5152
查看次数

How to use a Grid with Bindable Layout (more than one column)

In Xamarin.Forms 3.5 Microsoft introduced us to bindable layouts which can be used to dynamically fill layouts (e.g. StackLayout, Grid, etc.).

To use this in a grid with a single column is pretty straightforward:

<Grid BindableLayout.ItemsSource="{Binding Items}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <Label Text="{Binding MyProperty}"/>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</Grid>
Run Code Online (Sandbox Code Playgroud)

Now my question is how this can be used to populate a grid with more than one column due to the fact that DataTemplate only allows one view as content. Sure I could …

grid layout bindable xamarin xamarin.forms

5
推荐指数
1
解决办法
6842
查看次数

如何在 Prism 应用程序中手动解析类型时获取正确的 INavigationService 实例

似乎当我手动解析一个类型并请求INavigationService其中注入一个与其他地方使用的实例不同的实例时。

为了澄清我的用例,这里摘录了相关文件。正如您所看到的,在解析类型时SampleProcessINavigationService被注入,但实例与我获得的实例不同ProcessService。(顺便说一句,这是正确的实例,可以用于导航。注入的实例SampleProcess不能用于导航。)

任何想法为什么会发生这种情况,更重要的是我如何获得正确的实例INavigationService注入SampleProcess。是的,我可以通过使用方法传递它来提供它,但这并不是那么漂亮。

应用程序.xaml.cs

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.RegisterSingleton<ProcessService>();
    containerRegistry.Register<Processes.SampleProcess>();
}
Run Code Online (Sandbox Code Playgroud)

流程服务.cs

public class ProcessService
{
    private readonly IContainer container;
    private readonly INavigationService navigationService;

    public ProcessService(IContainer container, INavigationService navigationService)
    {
        this.container = container;
        this.navigationService = navigationService;
    }

    public void ExecuteProcess(ProcessEnum processEnumValue)
    {
        Type processType = processEnumValue switch
        {
            ProcessEnum.SampleProcess => typeof(Processes.SampleProcess),
            _ => throw new NotImplementedException()
        };

        var process = App.Current.Container.Resolve(processType) as IProcess;

        bool …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection prism xamarin xamarin.forms

5
推荐指数
1
解决办法
431
查看次数