/// <remarks>非同期操作中はこのメソッドを実行することはできません。同時にダーティフラグもクリアされます</remarks>
public async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
{
- try
- {
- await this.buffer.LockAsync().ConfigureAwait(false);
- StringBuilder line = new StringBuilder();
- for (int i = 0; i < this.Length; i++)
- {
- char c = this[i];
- line.Append(c);
- if (c == Document.NewLine || i == this.Length - 1)
- {
- string str = line.ToString();
- str = str.Replace(Document.NewLine.ToString(), fs.NewLine);
- await fs.WriteAsync(str).ConfigureAwait(false);
- line.Clear();
- if (tokenSource != null)
- tokenSource.Token.ThrowIfCancellationRequested();
-#if TEST_ASYNC
- System.Threading.Thread.Sleep(10);
-#endif
- }
- }
- this.Dirty = false;
- }
- finally
- {
- this.buffer.UnLock();
- }
+ await this.buffer.SaveAsync(fs, tokenSource);
+ this.Dirty = false;
}
/// <summary>
} while (readCount > 0);
}
+ internal async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
+ {
+ try
+ {
+ await this.LockAsync().ConfigureAwait(false);
+ StringBuilder line = new StringBuilder();
+ for (int i = 0; i < this.Length; i++)
+ {
+ char c = this[i];
+ line.Append(c);
+ if (c == Document.NewLine || i == this.Length - 1)
+ {
+ string str = line.ToString();
+ str = str.Replace(Document.NewLine.ToString(), fs.NewLine);
+ await fs.WriteAsync(str).ConfigureAwait(false);
+ line.Clear();
+ if (tokenSource != null)
+ tokenSource.Token.ThrowIfCancellationRequested();
+#if TEST_ASYNC
+ System.Threading.Thread.Sleep(10);
+#endif
+ }
+ }
+ }
+ finally
+ {
+ this.UnLock();
+ }
+ }
+
internal void ReplaceRegexAll(LineToIndexTable layoutlines, Regex regex, string pattern, bool groupReplace)
{
for (int i = 0; i < layoutlines.Count; i++)