Dispose of RichTextBox fixed

This commit is contained in:
niksedk 2014-08-27 14:09:32 +02:00
parent 516b93a9c1
commit 2b2b7a4077
12 changed files with 85 additions and 21 deletions

View File

@ -212,6 +212,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
} }
rtBox.Dispose();
} }
else if (italic) else if (italic)
{ {

View File

@ -35,7 +35,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = ToF4Text(subtitle, title); rtBox.Text = ToF4Text(subtitle, title);
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
@ -59,8 +61,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
string text = rtBox.Text;
LoadF4TextSubtitle(subtitle, rtBox.Text); rtBox.Dispose();
LoadF4TextSubtitle(subtitle, text);
} }
} }
} }

View File

@ -59,7 +59,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = sb.ToString(); rtBox.Text = sb.ToString();
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
private TimeCode DecodeTimeCode(string timeCode) private TimeCode DecodeTimeCode(string timeCode)

View File

@ -50,8 +50,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var lines2 = new List<string>(); var lines2 = new List<string>();
foreach (string line in rtBox.Lines) foreach (string line in rtBox.Lines)
lines2.Add(line); lines2.Add(line);
rtBox.Dispose();
text = new StringBuilder(); text = new StringBuilder();
var u52 = new UnknownSubtitle52(); var u52 = new UnknownSubtitle52();
u52.LoadSubtitle(subtitle, lines2, fileName); u52.LoadSubtitle(subtitle, lines2, fileName);
_errorCount = u52.ErrorCount; _errorCount = u52.ErrorCount;

View File

@ -59,7 +59,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = sb.ToString(); rtBox.Text = sb.ToString();
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
private TimeCode DecodeTimeCode(string timeCode) private TimeCode DecodeTimeCode(string timeCode)
@ -79,19 +81,24 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string text = string.Empty;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
text = rtBox.Text.Replace("\r\n", "\n");
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
lines = new List<string>(); lines = new List<string>();
string text = rtBox.Text.Replace("\r\n", "\n");
foreach (string line in text.Split('\n')) foreach (string line in text.Split('\n'))
lines.Add(line); lines.Add(line);

View File

@ -88,19 +88,24 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string text = string.Empty;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
text = rtBox.Text.Replace("\r\n", "\n");
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
lines = new List<string>(); lines = new List<string>();
string text = rtBox.Text.Replace("\r\n", "\n");
foreach (string line in text.Split('\n')) foreach (string line in text.Split('\n'))
lines.Add(line); lines.Add(line);

View File

@ -35,7 +35,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = base.ToText(subtitle, title); rtBox.Text = base.ToText(subtitle, title);
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
@ -49,18 +51,23 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r", string.Empty).Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
var arr = rtBox.Text.Replace("\r", string.Empty).Split('\n');
lines = new List<string>(); lines = new List<string>();
foreach (string s in arr) foreach (string s in arr)
lines.Add(s); lines.Add(s);

View File

@ -35,7 +35,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = base.ToText(subtitle, title); rtBox.Text = base.ToText(subtitle, title);
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
@ -49,19 +51,25 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r\n", "\n").Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
var list = new List<string>(); var list = new List<string>();
foreach (string s in rtBox.Text.Replace("\r\n", "\n").Split('\n')) foreach (string s in arr)
list.Add(s); list.Add(s);
base.LoadSubtitle(subtitle, list, fileName); base.LoadSubtitle(subtitle, list, fileName);
} }

View File

@ -35,7 +35,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = base.ToText(subtitle, title); rtBox.Text = base.ToText(subtitle, title);
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
@ -49,19 +51,25 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r\n", "\n").Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
var list = new List<string>(); var list = new List<string>();
foreach (string s in rtBox.Text.Replace("\r\n", "\n").Split('\n')) foreach (string s in arr)
list.Add(s); list.Add(s);
base.LoadSubtitle(subtitle, list, fileName); base.LoadSubtitle(subtitle, list, fileName);
} }

View File

@ -56,7 +56,9 @@ ST 0 EB 3.10
} }
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = sb.ToString(); rtBox.Text = sb.ToString();
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
private string EncodeTimeCode(TimeCode time) private string EncodeTimeCode(TimeCode time)
@ -79,20 +81,26 @@ ST 0 EB 3.10
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r\n", "\n").Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
Paragraph p = null; Paragraph p = null;
subtitle.Paragraphs.Clear(); subtitle.Paragraphs.Clear();
foreach (string line in rtBox.Text.Replace("\r\n", "\n").Split('\n')) foreach (string line in arr)
{ {
if (regexTimeCodes.IsMatch(line.Trim())) if (regexTimeCodes.IsMatch(line.Trim()))
{ {

View File

@ -53,7 +53,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = sb.ToString(); rtBox.Text = sb.ToString();
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
private string EncodeTimeCode(TimeCode time) private string EncodeTimeCode(TimeCode time)
@ -72,22 +74,27 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
bool expectStartTime = true; bool expectStartTime = true;
var p = new Paragraph(); var p = new Paragraph();
subtitle.Paragraphs.Clear(); subtitle.Paragraphs.Clear();
foreach (string line in rtBox.Text.Replace("\r", "").Split('\n')) foreach (string line in arr)
{ {
string s = line.Trim().Replace("*", string.Empty); string s = line.Trim().Replace("*", string.Empty);
var match = regexTimeCodes.Match(s); var match = regexTimeCodes.Match(s);

View File

@ -49,7 +49,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Text = sb.ToString(); rtBox.Text = sb.ToString();
return rtBox.Rtf; string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
} }
private string EncodeTimeCode(TimeCode time) private string EncodeTimeCode(TimeCode time)
@ -68,20 +70,26 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (!rtf.StartsWith("{\\rtf")) if (!rtf.StartsWith("{\\rtf"))
return; return;
string[] arr = null;
var rtBox = new System.Windows.Forms.RichTextBox(); var rtBox = new System.Windows.Forms.RichTextBox();
try try
{ {
rtBox.Rtf = rtf; rtBox.Rtf = rtf;
arr = rtBox.Text.Replace("\r", "").Split('\n');
} }
catch (Exception exception) catch (Exception exception)
{ {
System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.WriteLine(exception.Message);
return; return;
} }
finally
{
rtBox.Dispose();
}
var p = new Paragraph(); var p = new Paragraph();
subtitle.Paragraphs.Clear(); subtitle.Paragraphs.Clear();
foreach (string line in rtBox.Text.Replace("\r", "").Split('\n')) foreach (string line in arr)
{ {
string s = line.Trim(); string s = line.Trim();
if (s.StartsWith("[") && s.EndsWith(">") && s.Length > 13 && s.Substring(12, 1) == "]") if (s.StartsWith("[") && s.EndsWith(">") && s.Length > 13 && s.Substring(12, 1) == "]")