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.