473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

BackgroundWorker Problem


I would like to be able to pass the BackgroundWorker object and DoWork Event
Args to a second function (third function?) and be able to still report the
progress.

I'm getting the following exception when trying to access
BackgroundWorker.CancellationPending or e.Cancel

An unhandled exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an
invocation.

The problem is I can't stuff everything into the DoWork event to accomplish
what I want, but need to call another function which inturn calls a third
function.

I'm sure a code example would better explain:

main()

Dim bw as new BackgroundWorker

'Set bw properties (reports progress/support cancelation and call
DoWorkAsynch

End main
Sub bw_DoWork(sender As Object, e As DoWorkEventArgs) handles bw.DoWork

'Get the BackgroundWorker object that raised this event.
Dim worker as BackgroundWorker = cType(sender, BackgroundWorker)

'I have multiple arguments to pass
Dim args As EncryptFileArgs = cType(e.Argument, EncryptFileArgs)

e.Result = mEncryptFile(args.fileIn, args.fileOut, args.keySize, _
args.password, args.fileExpireTime, worker, e)

End sub

Function mEncryptFile( fileIn, fileOut,keySize, _
password, bworker as BackgroundWorker, e as
DoWorkEventArgs) as Boolean

'I need to do some pre-processing here

return EncryptFile(keys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, e)

End Function
'The actual encryption/work goes here
EncryptFile(keys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, e)

'Report Progress
bw.ReportProgress(percent)

'Check if user canceled 'This line throws the exception
If bw.CancellationPending Then
e.Cancel = true

End Function

Thanks in advance for any help,

Chris

Apr 9 '07 #1
0 2442

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dm1608 | last post by:
Hi -- I have a C# application that basically has a button that executes a SQL Reader to loop thru a rather large resul set. Thru each interation of the reader object, I check to see if a file...
2
by: Sebastian Crewe | last post by:
Greetings, I was much encouraged to see the new BackgroundWorker class in .NET v2. On the face of it, much easier to use than the various delegates and events of yore, though I imagine the same...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
5
by: redear | last post by:
Is there a way to immediately terminate a BackgroundWorker thread? My problem is that the BackgroundWorker starts with a call to My.Computer.FileSystem.GetFiles that can run for a very long time if...
2
by: Chris | last post by:
When I try to access the backgroundWorker.CancellationPending property I get the following exception: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
0
Plater
by: Plater | last post by:
So it occured to me that I told people to use this to solve some thread-safeing issues, but that I had not been using it myself (I had been using a delegate with invokerequired which seemed to lock...
4
by: =?Utf-8?B?U3ZlbiBXLg==?= | last post by:
Hi Newsgroup, I am developing a C# Windows Forms application that launches processes within a background worker.. The processes seem to have a memory limit of about 278mb. Some proccesses...
1
by: schnandr | last post by:
Hi, I have a user control which contains ListView. I copy all ListViewItems into a separate List<ListViewItemcalled unfilteredItems. I am using a BackgroundWorker to filter the ListView. When...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.