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