Background Thread causing System.Reflection.TargetInvocationException
I set up a background thread to show progress information on the screen while my main process is running. I am updating one of three datagridviews, and adjust a progress bar in each call to the background thread. I believe that I am getting a collision in different calls to the worker.ReportProgress. That is I think a new call is arriving before a prior call finishes, throwing the System.Reflection.TargetInvocationException.
Any suggestions on how to resolve this? If this is the problem, then minimizing the time in in the ReportProcess procedure, or lengthening the time between calls would fix the problem, but this seems arbitrary.
Re: Background Thread causing System.Reflection.TargetInvocationException
not much can be said without you posting some stripped down code to illustrate and ideally reproduce the problem. if it is a cross thread issue then lengthening or shortening some time is defenitely not the right way to fix anything.
Re: Background Thread causing System.Reflection.TargetInvocationException
I am trying to shift some of the processing out of the background procedure and see if that takes care of my problem. If that does not work I will likely come back and post some stripped down code.
Re: Background Thread causing System.Reflection.TargetInvocationException
you need to be aware of what ressources (objects etc) you access from what thread and that any thread can be interupted anytime. so you must take care of conflicts in accessing shared ressources.
Re: Background Thread causing System.Reflection.TargetInvocationException
I am dealing only with progress bars and datagridviews.
I only access the progress bar in the background thread so that should be clean
I make make all changes to the dgv in the background thread. i pass in the fields and add rows in the background. I also am changing some colors of cells in the background. I the foreground I do get the number of rows in the background and do read information out of the dgv.
Re: Background Thread causing System.Reflection.TargetInvocationException
Quote:
Originally Posted by
John_SC
I am dealing only with progress bars and datagridviews.
I only access the progress bar in the background thread so that should be clean
I make make all changes to the dgv in the background thread. i pass in the fields and add rows in the background. I also am changing some colors of cells in the background. I the foreground I do get the number of rows in the background and do read information out of the dgv.
That is pretty much your problem then, you are accessing user interface elements from a background thread. This is a big no-no, you can only access the UI from the main UI thread.
http://www.vbforums.com/showthread.p...ding-in-VB-Net is probably something you will find worth a read.