Skip to Content
Nov 03, 2016 at 02:55 PM

Long running task halts the SAP UI

576 Views Last edit Nov 03, 2016 at 03:29 PM 3 rev

I am using the C#API for UI and DI for SAP9.2 and working with forms. I created my forms as the SDK Help shows, but I am wondering how can I execute Tasks on different Thread than the UI Thread.

I need to load all the Items from OITM (28k) and run other queries as well, it usually completes in 5 seconds, but for the time it is running the SAP Completely stops being functional, you can't click on any other menu or do anything. Usually, when you write a desktop software with GUI, on one thread runs the GUI and you can do long running processes on a new background Thread and Display a progress bar on the gui. I should achieve something similar, not blocking the whole application. Can I display a progress indicator at least?

My Form calls my Data Access layer, passing the SBOApplication as a parameter, then creating a Company object from that. Than I run the queries and get the result as XML from the recordset (oRecordset.GetAsXML();) and parse the results. Should I just run the Queries on a different Thread myself in my addon and use the "Application.StatusBar.CreateProgressBar(...)" ProgressBar object to display the state?

I tried with the following code:

 Dal.Items itmsDao = new Dal.Items(SBOApp);
            ProgressBar oProgressBar = SBOApp.StatusBar.CreateProgressBar("Termékek betöltése...", 100, false);
            var worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;
            worker.DoWork += new DoWorkEventHandler(delegate (object o, DoWorkEventArgs args)
                BackgroundWorker b = o as BackgroundWorker;
                var itemList = itmsDao.GetItems(itemParamters);
                var filteredItems = FilterItems(itemList, itemParamters);
                var arlsitaItems = FillPrices(filteredItems);

            worker.ProgressChanged += new ProgressChangedEventHandler(delegate (object o, ProgressChangedEventArgs args)
                oProgressBar.Value = args.ProgressPercentage;

            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate (object o, RunWorkerCompletedEventArgs args)


The Progress bar is displayed, the addon's UI won't respond to any interaction (i am okay with that), other parts of the SAP UI is working while it is processing. Is there a better way in SAP Addon development (best practice) or my approach should work in production?

Edit: Also, this solution has an error, It only works the first time, the second time it throws an Exception ( $exception {"Progress Bar - has stopped [66000-88]"} System.Runtime.InteropServices.COMException)