473,226 Members | 1,288 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,226 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

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

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

I'm sure a code example would better explain:


Dim bw as new BackgroundWorker

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

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

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

End Function

Thanks in advance for any help,


Apr 9 '07 #1
0 2429

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

Similar topics

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...
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...
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...
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...
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...
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...
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...
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...
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...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.