|
-
Sep 7th, 2011, 08:08 AM
#1
Thread Starter
Fanatic Member
Threading WithEvents
I have an application that performs a lot of busy work. All of the work is performed using a BackgroundWorker and the point of execution is the DoWork Event of the BackgroundWorker.
On the UI thread, before the workload begins, I display a PictureBox that contains an animated GIF that illustrates progress; for the most part this works fine and the UI thread is not paused or slowed while the BackgroundWorker does its job. There is however, one instance where the UI thread is impacted by the work being done and it defeats the whole purpose of putting this work in a separate thread. In this application, the user must wait until the work completes before they can move to the next step, so my sole reason for moving this all to a BackgroundWorker was so that I could display a smooth, uninterrupted progress indicator on the UI thread while this work was being done, so that the user could see that something was happening.
The case where the work being done is impacting the UI thread (pausing/delaying the PictureBox animation) deals with a referenced COM object.
I have the following declared in my form:
vb.net Code:
Private WithEvents oCOMObject as X
The COM object performs some processing when given a list of files and it is here where the majority of the lag takes place. In my BackgroundWorker's DoWork Event I have the following:
vb.net Code:
'instantiate the COM object
oCOMObject = New X
'process the list of images (oFileList is a list of file paths on the system)
oCOMObject.ProcessFiles (oFileList) 'it is here that the UI thread is delayed
All of the COM object event handlers and subsequent functions are appropriately using Delegates, but I am not sure why the ProcessFiles method would cause the UI thread to hang while the work completes; I thought that was the whole purpose of the BackgroundWorker.
Am I missing something? Any thoughts?
Thanks!
-
Sep 7th, 2011, 08:15 AM
#2
Re: Threading WithEvents
What exactly does this mean?
All of the COM object event handlers and subsequent functions are appropriately using Delegates
If you're saying that you are invoking a method on the UI thread then that would likely explain the issue. How often are those event handlers executed and what exactly do they do?
-
Sep 7th, 2011, 08:23 AM
#3
Thread Starter
Fanatic Member
Re: Threading WithEvents
Here is a sample of one of the functions that is called from the oCOMObject event handler:
vb.net Code:
'if an invoke is required
If Me.InvokeRequired Then
'invoke the function safely
Me.Invoke(New RecordCompleteDelegate(AddressOf RecordComplete), iRecordIndex)
Else 'on appropriate thread
'perform work
End if'if an invoke is required
Some of the work that needs to be done is on the UI thread, so I do invoke methods accordingly; in this case I would understand the lag, but it is the method call to .ProcessFiles that is impacting the UI thread, which I don't understand. The method takes about 2 seconds to complete and the UI is hung for those 2 seconds (prior to ANY event handling or invoking of any kind).
Hope that helps explain what I mean.
-
Sep 7th, 2011, 08:27 AM
#4
Re: Threading WithEvents
In that case, I have no specific explanation. Maybe it's a COM thing.
-
Sep 8th, 2011, 12:46 PM
#5
Thread Starter
Fanatic Member
Re: Threading WithEvents
 Originally Posted by jmcilhinney
In that case, I have no specific explanation. Maybe it's a COM thing.
Not sure I have ever seen you say that ;o)
Any other ideas here?
-
Sep 8th, 2011, 02:46 PM
#6
Re: Threading WithEvents
It may be a COM thing... or something specific to the this COM thing... something tells me that because it's a COM component that it's going to want to run on the main thread and not the background one... but I don't think I could point to anything specific.
-tg
-
Sep 8th, 2011, 03:00 PM
#7
Thread Starter
Fanatic Member
Re: Threading WithEvents
 Originally Posted by techgnome
It may be a COM thing... or something specific to the this COM thing... something tells me that because it's a COM component that it's going to want to run on the main thread and not the background one... but I don't think I could point to anything specific.
-tg
Damn COM...wish I didn't have to use it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|