How to keep .Net 4.0 behavior if .Net 4.5 is installed?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 08:19:54

问题


We have a Windows Form application that targets .Net Framework 4.0. After installing .Net Framework 4.5, the application starts crashing. We'll have to investigate the crashes and we'll most probably have to fix things on our side. But is there a setting we can turn on to keep the old behavior until we are ready to use .Net 4.5?


Update 07/12/2012: We found the breaking change that causes our application to crash: Given a System.Threading.Timer, when calling Dispose(WaitHandle) with an handle that has already been closed, then the Timer tries to signal the WaitHandle which throws an exception. The .Net 4.0 implementation of Timer was tolerant to that but 4.5 is not.

There is a bug on our side; we don't have any good reason to give it a closed handle so we'll just fix that...until we find another bug...


回答1:


But is there a setting we can turn on to keep the old behavior until we are ready to use .Net 4.5?

No. .NET 4.5 is an in-place replacement of .NET 4. When you install it, you're effectively running on the new framework.

In general, it should be completely backwards compatible, but there are a few breaking changes.

Unfortunately, this is going to mean that you (and everyone else) will need to test and fix problems on both frameworks if you want to support running on a machine with 4.5 installed and without 4.5 installed. Luckily, the breaking changes are typically all unusual, edge cases, so it's unlikely to impact most users in most scenarios.




回答2:


I discussed this over email with original question poster - "Sly". Thanks Sly for helping investigate. It turns out that .NET4 and .NET4.5 behave the same way for Dispose(waithandle) API. So this problem is potentially unrelated to .NET4.5.

    static void Main(string[] args)
    {
        System.Threading.Timer timer = new System.Threading.Timer(new System.Threading.TimerCallback(blah));
        System.Threading.EventWaitHandle eventWaitHandle = new System.Threading.EventWaitHandle(true, System.Threading.EventResetMode.ManualReset);

        eventWaitHandle.Dispose();
        System.Threading.Thread.Sleep(2000);
        timer.Dispose(eventWaitHandle);
    } 

    private static void blah(object state)
    {
        Console.WriteLine(40);
    }


来源:https://stackoverflow.com/questions/11458159/how-to-keep-net-4-0-behavior-if-net-4-5-is-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!