I am trying to do the export in a background worker.
Does anyone have this working? What are the tricks to get it to work.
I implemented it the simple way with a backgroundworker, DoWoker,,,and I get an exception associated with TSA...
Any clues would be appriciated.
Hello,
This is because the background worker will try to execute this on a background thread and the exporting process will try to access the XamDataGrid, which is created on the UI thread. What you need to do is to use Dispatcher.BeginInvoke() when exporting :
BackgroundWorker worker = new BackgroundWorker ();
public MainWindow()
{
InitializeComponent();
worker.DoWork += new DoWorkEventHandler (worker_DoWork);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
DataPresenterExcelExporter exporter = new DataPresenterExcelExporter ();
Dispatcher.BeginInvoke(
new Action (() =>
exporter.Export(this .xamDataGrid1, "exported.xlsx" , WorkbookFormat .Excel2007);
}), null );
private void Button_Click(object sender, RoutedEventArgs e)
worker.RunWorkerAsync();
Thanks for the quick reply.
I tried this already, and yes, it does process the code in a new thread, but the previous thread waits for this new thread to be completed.
What I fundamentally need is two processes, one for the main app, and a second one for saving the data to excel. These processes need to be independent(that is why I am calling processes) so, while I am saving to the excel format, I can go back into the main process and do other things.
This example helps group the grid with the saving to ensure that this process is atomic, but it does not provide the parrallelism that I am looking for.
Any help down this path would be appriciated.
Restating my problem a bit clearer:
I have an application that has as one option a xamdatagrid which I am trying to export to. When I export a very large file, I would like to do other things in the application while the file is being saved. The aforementioned code, allows me to access the xamDataGrid and do the export, but it does not achieve the goal of letting me do other things in the application (eg. accessing other functionality that is totally disconnected with this task) . I smiluate a large excel save with the following code, and try to do something else to no avail.
System.Threading.
Thread.Sleep(10000);
}),
);
So, yes, I am running the work in a new thread, yet I do not have access to the remaining code.
Any help would be much appriciated.
Jack
is there a solution to this?
There is asynchronous support in the DataPresenterExcelExporter and DataPresenterWordWriter that was added in NA 11.1. You would use one of the ExportAsync overloads instead of the Export overloads. It is important to note that this is still done on the UI thread since it is dealing with objects that have thread affinity (e.g. the source grid and likely the datasource too) but the work is broken up to avoid locking the UI thread. The AsyncExportDuration determines the amount of time that will be spent exporting for each time slice and the AsyncExportInterval determines the amount of time to wait in between each time slice.
Hi !
I'm encoutering the same issue : no way to do an asychronous excel export. XamDataGrid is locked up.
To you have any news about the asynchrnous exporting ?
Yes, there is a plan that we have Asynchronous exporting in separate thread in the future.
Is there a plan to allow Excel Exporting in a separate theread, without these work arounds?
HI,
I agree with your workarounds. In a BackGround Worker threa,d create the Excel Workbook using the DataSource. Here a help link to our Excel Engineer
http://help.infragistics.com/NetAdvantage/WPF/2010.3/CLR4.0/?page=WPF_Infragistics_Excel_Engine.htmlSincerely,
MattDeveloper Support Engineer