Exception when accessing backgroundWorker.CancellationPending

C

Chris

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
 
C

Chris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top