471,123 Members | 893 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,123 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 4664
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by elziko | last post: by
7 posts views Thread by Chris | last post: by
1 post views Thread by ditnooitlezen | last post: by
4 posts views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post: by
7 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by

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.