小编Cha*_*ari的帖子

如何在F#中的异步工作流中重新使用?

在记录异常之后,我需要重新执行异步块时发生的异常.

当我执行以下操作时,编译器认为我没有在处理程序中调用reraise函数.我究竟做错了什么?

let executeAsync context = async {
    traceContext.Properties.Add("CorrelationId", context.CorrelationId)
    try
        do! runAsync context
        return None
    with
        | e when isCriticalException(e) ->
            logCriticalException e
            reraise()
        | e ->
            logException e
            return Some(e)
}
Run Code Online (Sandbox Code Playgroud)

f# asynchronous exception-handling f#-async

11
推荐指数
3
解决办法
1393
查看次数

OWIN中间件被调用的次数比预期的多,我还缺少什么?

我正在测试OWIN中间件,并编写了以下中间件类。但是奇怪的是,当我请求没有任何路径(localhost:<port>)的URL时,我总共调用此中间件大约四次。但是,当我打电话localhost:<port>/welcome.htm或我打电话时,localhost:<port>/default.htm它仅被调用一次,如预期的那样。我想念什么?

public class MyMiddleware : OwinMiddleware
{
    public MyMiddleware(OwinMiddleware next)
        : base(next)
    {
    }

    public override async Task Invoke(IOwinContext context)
    {
        await this.Next.Invoke(context);

        if (context.Request.Path.HasValue && (context.Request.Path.Value == "/" || context.Request.Path.Value.EndsWith(".htm")))
        {
            using (var writer = new StreamWriter(context.Response.Body))
            {
                await writer.WriteLineAsync("Next middleware: " + this.Next.ToString());
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的启动配置:

    public void Configuration(IAppBuilder appBuilder)
    {
        appBuilder.UseErrorPage(new ErrorPageOptions {
            ShowCookies = true,
            ShowEnvironment = true,
            ShowExceptionDetails = true,
            ShowHeaders = true,
            ShowQuery = true,
            ShowSourceCode …
Run Code Online (Sandbox Code Playgroud)

iis owin katana

5
推荐指数
0
解决办法
519
查看次数

使用Async.Catch处理进程损坏的状态异常

我需要在我的应用程序中知道动态执行的底层组件何时抛出进程损坏的状态异常,以便我可以记录它,并将该组件标记为再次加载并使我的进程崩溃.

这个组件的执行是异步执行的,我使用Async.Catch来处理该异常.我尝试了以下代码来测试Async.Catch的行为,在我看来Async.Catch是挂起的.这对我来说是一种不良影响,我怀疑所有PCSE都会导致相同的行为.

有谁知道如何摆脱这种情况?

let a = async {
    System.Threading.Thread.CurrentThread.Abort()
}

let b = async {
    let! m = Async.Catch a
    return match m with
            | Choice1Of2 p -> "hello"
            | Choice2Of2 e -> "Caught: " + e.ToString()
}

Async.RunSynchronously b;;
Run Code Online (Sandbox Code Playgroud)

编辑1:我发现,指着我为使用的文档HandleProcessCorruptedStateExceptionsAttribute一起SecurityCriticalAttribute,或使用一个配置项legacyCorruptedState­­ExceptionsPolicy=true.如果可能的话,我不想使用配置条目.

编辑2:根据评论中的建议,我修改了'b'的let绑定,如下所示:

let b = async {
        try
            let! m = Async.Catch a
            return "hello"
        with
            | :? System.Threading.ThreadAbortException as e -> return "Caught: " + e.ToString()
    }
Run Code Online (Sandbox Code Playgroud)

程序仍然挂起而不返回或投掷.

f# asynchronous exception-handling

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

标签 统计

asynchronous ×2

exception-handling ×2

f# ×2

f#-async ×1

iis ×1

katana ×1

owin ×1