小编02A*_*ant的帖子

如何在WPF中获取ComboBox.SelectedText

在WPF中,ComboBox没有SelectedText属性.

有没有办法实现与TextBox SelectedText在WPF中相同的功能

wpf

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

在C#中使用MemoryStream进行Xml架构验证失败

这是我的功能.

如果将MemoryStream传递给XmlReader,它有时不会验证正确的xml文件.我将XmlDocument对象存储在内存中,我想根据最终用户提供的xsd Schema文件对其进行验证.

ValidateSchema1(string XMLPath, string XSDPath)
    {
        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.Load(XMLPath);

          using (MemoryStream mstream = new MemoryStream())
          {
              //StreamWriter writer = new StreamWriter(mstream);
              xmlDocument.Save(mstream);
              mstream.Seek(0, SeekOrigin.Begin);
              XmlSchemaSet sc = new XmlSchemaSet();

              // Add the schema to the collection.
              sc.Add(null, XSDPath);

              // Set the validation settings.
              XmlReaderSettings settings = new XmlReaderSettings();
              settings.ValidationType = ValidationType.Schema;
              settings.Schemas = sc;
              settings.ValidationEventHandler += ValidationCallBack;

              // Create the XmlReader object.

              // Not woking
              XmlReader reader = XmlReader.Create(mstream, settings);

              // Working
              //XmlReader reader = …
Run Code Online (Sandbox Code Playgroud)

c# xml validation xsd

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

为什么ReadAsync在FileStream和C#中的StreamReader中更快?

我正在编写一种使用新的ReadAsync方法读取大文件的方法.在我的测试看起来像FileStream ReadAsync比StreamReader更快,不知道为什么?

ReadStreamReaderAsync

线程ID在等待之前:9

等待后的线程ID:13

时间:76626

总字节数:687184052

ReadFileStreamAsync

线程ID在等待之前:9

等待后的线程ID:10

时间:19167

总字节数:687184052

  static async Task<long> ReadStreamReaderAsync(string filename)
    {
        Console.WriteLine("Thread ID Before Await : {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
        long totalBytes = 0;
        var sp = new Stopwatch();
        sp.Start();
        using (StreamReader reader = new StreamReader(filename, Encoding.Default))
        {
            char[] buffer = new char[0x1000];
            int numRead;
            while ((numRead = await reader.ReadAsync(buffer, 0, buffer.Length)) != 0)
            {
                totalBytes += numRead;
            }
        }

        sp.Stop();
        Console.WriteLine("Thread ID After Await : {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
        Console.WriteLine("Time : {0}", sp.ElapsedMilliseconds);
        return totalBytes;
    } …
Run Code Online (Sandbox Code Playgroud)

async-await

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

标签 统计

async-await ×1

c# ×1

validation ×1

wpf ×1

xml ×1

xsd ×1