473,405 Members | 2,141 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,405 software developers and data experts.

Exception when accessing backgroundWorker.CancellationPending

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.

Here is the code:

private void backgroundWorkerEncryptFile_DoWork(object sender,
DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
EncryptFileArgs args = (EncryptFileArgs)e.Argument;
e.Result = mEncryptFile(args.fileIn, args.fileOut, args.keySize,
args.password, worker, e);
}

internal static bool mEncryptFile(string fileIn, string fileOut, int
keySize,
string password, BackgroundWorker
bworker, DoWorkEventArgs e)
{

// I can access bworker.CancellationPending just fine in here
//The problem is I need to do some pre-processing in here (to build up a
file header)
// but the actual encryption gets done via a call to another class

//pre-processing goes here

//Encrypt the file
Crypto_Provider.EncryptFile(keys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, ref e);

}

//This is in the Crypto_Provider class
internal static void EncryptFile(byte[] IV, byte[] key, int keySize,
string fileIn, ref FileStream fsOut,
BackgroundWorker bw, DoWorkEventArgs e)
{
//When I try and access bw.CancellationPending I get the exception

//Check if user canceled
if (bw.CancellationPending)
{
e.Cancel = true;
}

}

Thanks,

Any help is greatly appreciated.

Chris
Apr 12 '07 #1
2 4807
More information:

If I change Crypto_Provider to a partial class of the same name as the rest
of the code everything works just fine.

Why is this? What am I missing?

Thanks,

Chris
"Chris" <co***********@nospam.yahoo.comwrote in message
news:eE**************@TK2MSFTNGP04.phx.gbl...
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.

Here is the code:

private void backgroundWorkerEncryptFile_DoWork(object sender,
DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
EncryptFileArgs args = (EncryptFileArgs)e.Argument;
e.Result = mEncryptFile(args.fileIn, args.fileOut, args.keySize,
args.password, worker, e);
}

internal static bool mEncryptFile(string fileIn, string fileOut, int
keySize,
string password,
BackgroundWorker bworker, DoWorkEventArgs e)
{

// I can access bworker.CancellationPending just fine in here
//The problem is I need to do some pre-processing in here (to build up a
file header)
// but the actual encryption gets done via a call to another class

//pre-processing goes here

//Encrypt the file
Crypto_Provider.EncryptFile(keys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, ref e);

}

//This is in the Crypto_Provider class
internal static void EncryptFile(byte[] IV, byte[] key, int keySize,
string fileIn, ref FileStream fsOut,
BackgroundWorker bw, DoWorkEventArgs e)
{
//When I try and access bw.CancellationPending I get the exception

//Check if user canceled
if (bw.CancellationPending)
{
e.Cancel = true;
}

}

Thanks,

Any help is greatly appreciated.

Chris

Apr 13 '07 #2
This helped me at least. David Veeneman gave a solution here - http://www.thescripts.com/forum/thread519073.html.I'm not sure if this was the same for you case if it was fixed by simply making the file partial (although it sounds unreasonable) but this helped me

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 26 '07 #3

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

Similar topics

5
by: elziko | last post by:
I know I can stop my thread by using the CancelAsync method of the BackgroundWorker but that requires me to monitor the value of the CancellationPending property in my BackgroundWorker.DoWork...
2
by: Steve | last post by:
After running into a design wall with my traditional thread approach, I realized that a BackgroundWorker object would fit my needs pretty good. Never really used them before. In a nutshell, my...
7
by: Chris | last post by:
Hi everyone, I'm trying to find the fastest way to get all the files from the local c: drive. I have even considered the api calls findfirst/findnext, but read that in VB.net it's best to use...
1
by: ditnooitlezen | last post by:
Hi, the (.NET 2.0) backgroundworker object has a DoWork method that operates in a background thread. When the DoWork method is finished the RunWorkerCompleted event is raised in the parent...
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...
1
by: Maxwell | last post by:
So, I am building a class which implements the Event-based Asynchronous pattern. We'll call it MyClass. Suppose part of it looks like the following: /// <code> public class MyClass : Component...
4
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I have winForm that needs update Panel (add controls to Panel of SplitContainer dynamically). I have a Backgroundworker, and DoWork event I want to add controls but I get this...
7
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
How do you cancel a BackgroundWorker? For this BackgroundWorker: bgWorker.WorkerReportsProgress = true; bgWorker.WorkerSupportsCancellation = true; I have tried this, but it never exits the...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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...
0
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,...

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.