473,785 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception when accessing backgroundWorke r.CancellationP ending

When I try to access the backgroundWorke r.CancellationP ending property I get
the following exception:

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.

I am using the backgroundWorke r in a component that I am trying to make for
doing encryption of large files in the background.

Here is the code:

private void backgroundWorke rEncryptFile_Do Work(object sender,
DoWorkEventArgs e)
{
BackgroundWorke r worker = sender as BackgroundWorke r;
EncryptFileArgs args = (EncryptFileArg s)e.Argument;
e.Result = mEncryptFile(ar gs.fileIn, args.fileOut, args.keySize,
args.password, worker, e);
}

internal static bool mEncryptFile(st ring fileIn, string fileOut, int
keySize,
string password, BackgroundWorke r
bworker, DoWorkEventArgs e)
{

// I can access bworker.Cancell ationPending 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(ke ys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, ref e);

}

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

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

}

Thanks,

Any help is greatly appreciated.

Chris
Apr 12 '07 #1
2 4838
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.co mwrote in message
news:eE******** ******@TK2MSFTN GP04.phx.gbl...
When I try to access the backgroundWorke r.CancellationP ending property I
get the following exception:

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.

I am using the backgroundWorke r in a component that I am trying to make
for doing encryption of large files in the background.

Here is the code:

private void backgroundWorke rEncryptFile_Do Work(object sender,
DoWorkEventArgs e)
{
BackgroundWorke r worker = sender as BackgroundWorke r;
EncryptFileArgs args = (EncryptFileArg s)e.Argument;
e.Result = mEncryptFile(ar gs.fileIn, args.fileOut, args.keySize,
args.password, worker, e);
}

internal static bool mEncryptFile(st ring fileIn, string fileOut, int
keySize,
string password,
BackgroundWorke r bworker, DoWorkEventArgs e)
{

// I can access bworker.Cancell ationPending 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(ke ys.IV, keys.KQ,
keySize, fileIn,
ref fsOut, bworker, ref e);

}

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

//Check if user canceled
if (bw.Cancellatio nPending)
{
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.ht ml.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
2701
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 event. This means that if the DoWork event is processing a single line of code then my code must wait for this line to finish before it can check the value of CancellationPending. What if the user wants to cancel before I can check this value? Is...
2
5397
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 problem is cancelling the worker. I've read the MSDN docs, checked google and haven't found a solution. The problem is, once I make a call to cancellAsync() (I check for CancellationPending in my DoWork handler) and WorkerComplete fires, the...
7
4296
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 the GetFiles function. I'm using: Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*", IO.SearchOption.AllDirectories)
1
2908
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 thread. Now I have in the backgroundworker's DoWork method a try catch finally block, like this: StreamReader sr = null;
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...
1
1870
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 { private BackgroundWorker worker; public void MyMethodAsync()
4
4804
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 error in Spanish (I don't get translation: Los controles creados en un subproceso no pueden tener controles primarios en un control en un subproceso diferente.)
7
4808
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 do...while loop: if (bgWorker.IsBusy == true) {
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
9647
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
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
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...
0
9958
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...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5390
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...
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.