473,770 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackgroundWorke r Problem


I would like to be able to pass the BackgroundWorke r 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
BackgroundWorke r.CancellationP ending or e.Cancel

An unhandled exception of type 'System.Reflect ion.TargetInvoc ationException'
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 BackgroundWorke r

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

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

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

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

e.Result = mEncryptFile(ar gs.fileIn, args.fileOut, args.keySize, _
args.password, args.fileExpire Time, worker, e)

End sub

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

'I need to do some pre-processing here

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

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

'Report Progress
bw.ReportProgre ss(percent)

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

End Function

Thanks in advance for any help,

Chris

Apr 9 '07 #1
0 2480

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

Similar topics

2
9277
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 exists on the server. If it does, I update a textbox (multiline) with the missing file, update a status bar label, and a progressbar. Since this process is kind of lengthy, every 400 rows, I do a DoEvents() and TextBox.Refersh() to refresh the...
2
8749
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 base classes are being invoked. Anyway, I have given it a try with a VB.NET application that generates charts. Since there are some 3,000 charts to do, I wanted to put the chart generation on a separate thread. Works fine inasmuch as the...
5
14134
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
5
11236
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 it is pointing to a directory tree with many files. If the user requests cancellation during this time, the main thread can call CancelAsync and can post a "Cancellation Pending" message to the user, but the BackgroundWorker cannot respond to...
2
4838
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 mscorlib.dll Additional information: Exception has been thrown by the target of an invocation. I am using the backgroundWorker in a component that I am trying to make for doing encryption of large files in the background.
9
18034
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 will almost always lead to the user opening a certain child window that's fairly resource intensive to load. Is it possible to load this form in a backgroundworker and then use the Show method and hide method as necessary? Anyone know of
0
1081
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 up program on closing) Anyway, I've been using the example on msdn for using backgroundworker to do async stuff. The problem is IT STILL claims to be making unsafe thread calls. The setup for the backgroundworker: private BackgroundWorker...
4
6402
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 that get to that amount of used memory seem to hang ;-( Is there a memory limit that can be adjusted ?? The physical machine has 3
1
4801
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 I access this list in the DoWork Handler I am getting an InvalidOperationException that the List was not created by this thread. Is there a way to solve this problem?
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.