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?
I would also like to know answer for this question. Just like jack520 said, using BackgroundWorker or another thread while exporting freezes the UI. AFAIK using UI controls or their content in a thread does that.
After several attempts to tackle this I am came to a conclusion that if we want to use the Infragistics components and their methods you can do exporting at least partially on background. This can be done by extracting data from the datasource or datagrid to a Workbook and then using the Workbook.Save method on background thread. However, the save is a single method call so you wouldn't be getting any information about the progress to the UI.
Another alternative is to create a CSV file on background thread in the traditional way. This works just fine but if for example you want to export only the selected rows or your datagrid supports grouping... you have to support this in your code. However, if you have all those fancy features which allow you to export data by writing only a few lines of code, you probably want to use those which brings us back to the question - i there a better solution for exporting datagrid on background without UI freezing?
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