小编Jac*_*ack的帖子

DispatcherTimer不在WPF应用程序中触发

我试图理解为什么包含在其中的DispatcherTimer SingletonWithTimer未在以下WPF应用程序中触发.我已经研究了这几天了,似乎无法深究它.此应用程序是我正在尝试修复的现有应用程序的简化部分.这个项目的Startup对象是WPFApplication5TimerTest.Program.

控制台中的输出列表如下,问题很明显,因为输出中未显示" TimerTick " 字样:

Timer is initialized
'WpfApplication5TimerTest.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Sample thread
Sample thread
Sample thread
Sample thread
Sample thread
Sample thread
The thread '<No Name>' (0x10b0) has exited with code 0 (0x0).
Sample thread exiting!
Run Code Online (Sandbox Code Playgroud)

这是Program.cs:

using System;

namespace WpfApplication5TimerTest
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            AppObject = new App();
            AppObject.Run();
        } …
Run Code Online (Sandbox Code Playgroud)

wpf multithreading dispatchertimer

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

DataContractSerializer不反序列化引用

我使用.NET 3.5中的DataContractSerializer来反序列化xml.xml之前是从实体模型中的一组相关实体序列化的,由实体框架3.5支持.有许多引用,xml广泛地包含每个引用实体的成员和键的所有值.

顶级实体反序列化很好,但引用的实体不反.

这是我用来序列化和反序列化的代码:

    public static T DCDeserializeXml<T>(string xml)
    {
        MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(xml));
        using (
        XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, Encoding.Unicode,
                   new XmlDictionaryReaderQuotas(), null))
        {
            DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T), null, Int32.MaxValue, false, true, null);
            return (T)dataContractSerializer.ReadObject(reader, true);
        }
    }

    public static string DCSerializeToXml<T>(T obj)
    {
        DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T), null, Int32.MaxValue, false, true, null);

        String text;
        using (MemoryStream memoryStream = new MemoryStream())
        {
            dataContractSerializer.WriteObject(memoryStream, obj);                
            byte[] data = new byte[memoryStream.Length];
            Array.Copy(memoryStream.GetBuffer(), data, data.Length);
            text = Encoding.UTF8.GetString(data);
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework datacontractserializer

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