Hi Minh,
You could use a background thread that executes the Merge operation. In order to pass the document to execute on the background, you will need to export it and pass the result string to the other thread, which then could import it to create a RadDocument instance and merge the desired record from the source collection. Keep in mind that the thread must be with ApartmentState.STA.
Here is a sample code that uses a separate thread to perform a Mail Merge and save the document to the file system:
Hope this helps.
Regards,
Tanya
Telerik
You could use a background thread that executes the Merge operation. In order to pass the document to execute on the background, you will need to export it and pass the result string to the other thread, which then could import it to create a RadDocument instance and merge the desired record from the source collection. Keep in mind that the thread must be with ApartmentState.STA.
Here is a sample code that uses a separate thread to perform a Mail Merge and save the document to the file system:
XamlFormatProvider provider =
new
XamlFormatProvider();
string
editorDocument = provider.Export(
this
.editor.Document);
Thread thread =
new
Thread(() =>
{
RadDocument document = provider.Import(editorDocument);
document.MailMergeDataSource.ItemsSource =
new
ExamplesDataContext().Employees;
// The MailMerge() method will merge all the records in the MailMergeDataSource. If you need to merge only a single record, you could use MailMergeCurrentRecord()
RadDocument result = document.MailMerge();
PdfFormatProvider pdfProvider =
new
PdfFormatProvider();
using
(FileStream stream = File.OpenWrite(
"result.pdf"
))
{
pdfProvider.Export(result, stream);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Hope this helps.
Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.