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
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