当前位置: 首页>>代码示例>>C#>>正文


C# ILoader.Release方法代码示例

本文整理汇总了C#中ILoader.Release方法的典型用法代码示例。如果您正苦于以下问题:C# ILoader.Release方法的具体用法?C# ILoader.Release怎么用?C# ILoader.Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILoader的用法示例。


在下文中一共展示了ILoader.Release方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadFileAsync

        private async Task<Document> LoadFileAsync(ILoader loader, string path, CancellationToken cancellationToken)
        {
            try
            {
                using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
                using (var reader = new StreamReader(file))
                {
                    var count = 0;
                    var buffer = new char[4096];
                    while ((count = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0)
                    {
                        // Check for cancellation
                        cancellationToken.ThrowIfCancellationRequested();

                        // Add the data to the document
                        if (!loader.AddData(buffer, count))
                        {
                            throw new IOException("The data could not be added to the loader.");
                        }
                    }

                    return loader.ConvertToDocument();
                }
            }
            catch
            {
                loader.Release();
                throw;
            }
        }
开发者ID:Liquidize,项目名称:RMMVResourceManager,代码行数:30,代码来源:PreviewForm.cs

示例2: LoadDocument

 /// <summary>
 /// Loads a file using background document loader, background task (outside UI thread)
 /// </summary>
 /// <param name="loader">ILoader instance created with CreateLoader() method</param>
 /// <param name="path"></param>
 /// <param name="cancellationToken"></param>
 /// <param name="encoding"></param>
 /// <param name="detectBOM"></param>
 /// <returns></returns>
 private async Task<Document> LoadDocument(ILoader loader, string path, CancellationToken cancellationToken, Encoding encoding = null, bool detectBOM = true) {
     var buffer = new char[LoadingBufferSize];
     var count = 0;
     try {
         using (var file = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, bufferSize: LoadingBufferSize, useAsync: true)) {
             if (encoding != null) Encoding = encoding;
             else if (Encoding == null) Encoding = Encoding.UTF8;
             using (var reader = new StreamReader(file, Encoding, detectBOM, LoadingBufferSize)) {
                 while ((count = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) {
                     cancellationToken.ThrowIfCancellationRequested();
                     if (!loader.AddData(buffer, count)) throw new IOException("The data could not be added to the loader.");
                 }
                 return loader.ConvertToDocument();
             }
         }
     } catch {
         loader.Release();
         throw;
     }
 }
开发者ID:HTD,项目名称:TraxCodeEditor,代码行数:29,代码来源:CodeEditor.cs


注:本文中的ILoader.Release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。