How to increase background task performance in WPF?

I am creating a WPF application that will do the hard work in the background. The problem is that when I run the task in unit tests, it usually takes about 6-7 seconds to run. But when I launch it using TPL in a WPF application, it takes 12 to 30 seconds to start. Is there a way to speed this thing up. I am calling the COM api LogParser to do the real work.

Update : My code to call Log Parser API looks below

var thread = new Thread(() =>
            {
                var logQuery = new LogQueryClassClass();
                var inputFormat = new COMEventLogInputContextClassClass
                {
                    direction = "FW",
                    fullText = true,
                    resolveSIDs = false,
                    formatMessage = true,
                    formatMsg = true,
                    msgErrorMode = "MSG",
                    fullEventCode = false,
                    stringsSep = "|",
                    iCheckpoint = string.Empty,
                    binaryFormat = "HEX"
                };
                try
                {
                    Debug.AutoFlush = true;
                    var watch = Stopwatch.StartNew();
                    var recordset = logQuery.Execute(query, inputFormat);
                    watch.Stop();

                    watch = Stopwatch.StartNew();
                    while (!recordset.atEnd())
                    {
                        var record = recordset.getRecord();
                        recordProcessor(record);
                        recordset.moveNext();
                    }
                    recordset.close();
                    watch.Stop();
                }
                catch
                {
                }
                finally
                {
                    if (logQuery != null)
                    {
                        Marshal.ReleaseComObject(logQuery);
                        GC.SuppressFinalize(logQuery);
                        logQuery = null;
                    }
                }
            });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();

Now with this change, I see an improvement of 3-34 in debug mode, but not when I press Ctrl + F5 to start it, which is completely outside of me. How did it happen?

+5
source share
2

, COM-, , STA. , , . SDK LogParser, CLSID, MSUtil.LogQuery ProgID:

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66}]
@="LogQuery"
"AppID"="{3040E2D1-C692-4081-91BB-75F08FEE0EF6}"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66}\InprocServer32]
@="C:\\Program Files (x86)\\Log Parser 2.2\\LogParser.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66}\ProgID]
@="MSUtil.LogQuery.1"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66}\VersionIndependentProgID]
@="MSUtil.LogQuery"

, "ThreadingModel"="Apartment", clincher. COM , STA.

TPL, BackgroundWorker MTA. , LogParser TPL, BackgroundWorker COM , , , STA . ( , "host STA", , COM . , , . )

COM STA. Windows, ( , - , ), STA, STA , COM LogParser .

, API, .

WPF Windows Forms, . COM- STA , STA. ​​ , -STA-. TPL, BackgroundWorker - ​​ , , MTA, STA.

- STA. - . Thread System.Threading, . SetApartmentState . , , LogParser API, , , - . .

21 2013 , :

, , , COM- STA. , STA, . , STA , COM- . , , , . .NET, STA , , COM- , , , , .

, - , STA, STA, - .

25 2013 , :

( , , , .) , - , . INotifyPropertyChanged, WPF , . , , . - . , : http://www.interact-sw.co.uk/iangblog/2013/02/14/wpf-async-too-fast

+10

COM IPC. , , , , , Delphi Outlook . , COM- - , . Windows -, , . COM. , , COM .

+2

All Articles