internal static class RtfMerger
{
static object lockRtf = new object();
static RichTextBox richTextBox1 = new RichTextBox();
static TaskCompletionSource<string> source = new TaskCompletionSource<string>();
static Thread thread = new Thread(() =>
{
//SOME code...
// HOW TO THERE ACCESS TO THE PARAMETER input ?
});
public static Task<string> MergeRtf(params string[] input)
{
lock (lockRtf)
{
thread.SetApartmentState(ApartmentState.STA);
thread.Start(); // <- HERE I CAN PASS input
return source.Task;
}
}
Hello, how to modify declaration of thread, that it can receive parameter string[] input?
and there is full class with associated methods. hope it helps because I've been worried about it for a long time and I don't know what to do because I've been worried about it for a long time and I don't know what to do
{
internal static class RtfMerger
{
static object lockRtf = new object();
static RichTextBox richTextBox1 = new RichTextBox();
static TaskCompletionSource<string> source = new TaskCompletionSource<string>();
static Thread thread = new Thread(() =>
{
try
{
//var richTextBox1 = new RichTextBox(); //TODO static na úrovni třídy [LOCK] //TODO async
if (input != null && input.Length > 0)
{
if (input[0].StartsWith(@"{\rtf"))
{
richTextBox1.Rtf = input[0];
}
else
{
richTextBox1.Rtf = ConvertPlainTextToRTF(input[0], "Arial");
}
richTextBox1.AppendText("\r\n");
for (int i = 1; i < input.Length; i++)
{
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.SelectionLength = 0;
if (input[i].StartsWith(@"{\rtf"))
{
richTextBox1.SelectedRtf = input[i];
}
else
{
richTextBox1.SelectedRtf = ConvertPlainTextToRTF(input[i], "Arial");
}
}
}
source.SetResult(richTextBox1.Rtf);
}
catch (Exception ex)
{
source.SetException(ex);
}
});
public static Task<string> MergeRtf(params string[] input)
{
lock (lockRtf)
{
//TODO přidat synchronizační objekt (může být
thread.SetApartmentState(ApartmentState.STA);
thread.Start(); //Přidat zámek k spuštění threadu
return source.Task;
}
}
}
}