相关疑难解决方法(0)

当它被抛出并被捕获时,不要停止调试器

在工具/异常中,我设置了调试器在抛出异常时停止的选项.是否被抓住.

如何排除该规则的例外?在我的代码中的某处有一个被捕获的异常,它是程序逻辑的一部分.所以我显然不希望该异常在每次命中时停止调试器.

示例:我想忽略第344行的nullreference异常(捕获).我想停止所有其他例外

.net c# debugging .net-3.5 visual-studio-2008

91
推荐指数
4
解决办法
3万
查看次数

当涉及到可变值类型时,如何处理async/await产生的副作用?

请考虑以下示例代码:

using System.Diagnostics;
using System.Threading.Tasks;

public struct AStruct
{
    public int Value;

    public async Task SetValueAsync()
    {
        Value = await Task.Run(() => 1);
    }
    public void SetValue()
    {
        Value = 1;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Test(new AStruct());
        TestAsync(new AStruct()).Wait();
    }

    private static async Task TestAsync(AStruct x)
    {
        Debug.Assert(x.Value == 0);
        await x.SetValueAsync();
        Debug.Assert(x.Value == 0);
    }

    private static void Test(AStruct x)
    {
        Debug.Assert(x.Value == 0);
        x.SetValue();
        Debug.Assert(x.Value == 1);
    }
}
Run Code Online (Sandbox Code Playgroud)

注意之间的差异Test和 …

c# struct async-await

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

ContextBoundObject在等待之后引发远程处理错误

我有一些日志代码,使用ContextBoundObject和ContextAttribute编写拦截方法调用.该代码基于代码项目示例.

这一切都运行良好,直到我们开始使用此库与利用异步和等待的代码.现在我们在运行代码时遇到了远程错误.这是一个重现问题的简单示例:

public class OhMyAttribute : ContextAttribute
{
    public OhMyAttribute() : base("OhMy")
    {
    }
}

[OhMy]
public class Class1 : ContextBoundObject
{
    private string one = "1";
    public async Task Method1()
    {
        Console.WriteLine(one);
        await Task.Delay(50);
        Console.WriteLine(one);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我们调用时,Method1我们RemotingException在第二个上面得到以下内容Console.WriteLine:

Remoting cannot find field 'one' on type 'WindowsFormsApplication1.Class1'.
Run Code Online (Sandbox Code Playgroud)

有没有办法使用内置的C#方法来解决这个问题,还是我们必须看看像PostSharp这样的替代解决方案?

c# custom-attributes async-await

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