|
You can't cancel it because the BackgroundWorker uses a thread from the .NET thread pool, IIRC.
What I usually do, Luis, is have the background worker spawn yet another thread inside the DoWork event handler. That thread just sits there and monitors the thread for either completion or cancellation of the background worker. It looks something like this:
void worker_DoWork(object sender, DoWorkEventArgs e)
{
IAsyncResult result = myWebServiceMethodDelegate.BeginInvoke(...);
while(result.IsCompleted == false && this.backgroundWorker1.CancellationPending == false)
{
Thread.Sleep(...);
}
}
This way, if you cancel the background worker, your DoWork thread will return relatively quickly (as soon as it sees that CancellationPending is true).
Also, have a look at Roy Osherove's ExtendedBackgroundWorker[^], which addresses the problem you're running into.
|
|
|
|
|
I'm actually using remoting, so I don't have asynch methods to call. But creating another thread sounds like a good idea.
I'll take a detailed look at the page you suggest, it seems it will be of help!
Thanks!
Luis Alonso Ramos
Intelectix
Chihuahua, Mexico Not much here: My CP Blog!
|
|
|
|
|
Luis Alonso Ramos wrote: I'm actually using remoting, so I don't have asynch methods to call.
You can still do async calls using remoting. Just wrap your remote method in a delegate and call BeginInvoke on that delegate:
void MyRemoteMethod()
{
...
}
ThreadStart del = new ThreadStart(MyRemoteMethod);
del.BeginInvoke(...);
|
|
|
|
|
I'll take a look into that. Thanks, Judah!
Luis Alonso Ramos
Intelectix
Chihuahua, Mexico Not much here: My CP Blog!
|
|
|
|
|
Hopefully this will proove to be a classic school boy error, but I am damned if I can find the solution to this problem.
I have a project that has various class organised across various namespaces. If I use the following using statement:
using AndTheOther = Project.This.That.AndTheOther;
Everything work fine, i.e. I can call:
AndTheOther.MyRandomMethod();<br />
AndTheOther.MyRandomClass mrc = new MyRandomClass()<br />
However, if I use the following using statement:
using Project.This.That;
The compiler (VS 2003) fails with the usual
(144): The type or namespace name 'AndTheOther' could not be found (are you missing a using directive or an assembly reference?)
Can anybody tell me what I have got wrong?
|
|
|
|
|
It's Working As Designed. You can't partially resolve a namespace with a using statement, it's all or nothing.
|
|
|
|
|
OK I can live with that, thanks for the prompt reply.
Now just to test your skills further How about this pearl:
I have another namespace problem that I think may be related:
I have the following class:
<br />
namespace Where.No.Man.Has.Gone<br />
{<br />
class Before<br />
{<br />
.....<br />
}<br />
}<br />
In another area of the code I need to use the Before class, so I duly created a using statement for it and called the class:
<br />
using Where.No.Man.Has.Gone<br />
<br />
namespace Right.Here.Right<br />
{<br />
class Now<br />
{<br />
Before b = new Before()<br />
}<br />
}<br />
The compiler fails with this on the Before class initilialisation, but does work with this:
<br />
using Where.No.Man.Has.Gone<br />
<br />
namespace Right.Here.Right<br />
{<br />
class Now<br />
{<br />
Where.No.Man.Has.Gone.Before b = new Where.No.Man.Has.Gone.Before()<br />
}<br />
}<br />
The using statement is valid, as the compiler does raise an eyebrow at it.
|
|
|
|
|
Do you have another class named Before in either the current namespace of one of the other namespaces that you are using?
|
|
|
|
|
i want to learn how to create pop-up alert forms like the new-message alert in outlook 2003, the download-complete pop-up alert in firefox, and the pop-up alerts in instant messaging programs.
anybody know where i can find a good tutorial on this for beginners?
-- modified at 13:43 Monday 10th April, 2006
|
|
|
|
|
They're usually just modeless dialogs moved from outside the screen to (screen - left | screen - height)
Take a look here
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
|
thanks guys
|
|
|
|
|
How to set monitor application activity?
Need to have a list of all started applications!
If it is possible, please tell me... Or say in what way I must see!?
-- modified at 15:17 Monday 10th April, 2006
|
|
|
|
|
Sergey Gorchichko wrote: Need to have a list of all started applications!
System.Diagnostics.Process.GetProcesses
This question has been answered many, many times on this forum. Next time use the forum's search functionality before asking.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I know this namespace! But I can't understand the best algorithm to update the list of processes!!!
|
|
|
|
|
This is an issue in the sense that it's irritating me, but i'm sure it was designed as a feature. When using a DataGrid bound to a DataSet with sorting enabled, the scroll bar will tend to jump around . Here's what I'm trying to do. I have a DataGrid that will be displaying anywhere from 150 - 500 individual rows. These rows are constantly added/deleted/updated on a one second loop. The issue is when the user has scrolled down the list and clicked on an item. If they try to sroll back up then when the DataGrid updates with new rows, it will jump back to the last selected row. I've tried overriding the GridVScolled message and stored the origal position and then reapplying the position after sort. This works but if the row data changes then the scroll bar will jump to follow where it went. What I'm trying to get is a dumb scrollbar. I want the scrollbar to stay at Vertical position 16 if that's where the user put it no matter what the sort or active cell is. Any idea's where I should be headed on this. Thanks for the help.
Pseudo Quasi Coder
|
|
|
|
|
Can someane explain me how can i use a custom font that was added to my system in a windows forms application for .NET framework 2.0?
The font is available in my system but it isn't available in Visual Studio. Is it that i can only use fonts already contained in a assembly pre-packaged with the .net framework?
I wasn't able to find any information about fonts and windows forms on the web.
Help please!
|
|
|
|
|
|
I have a hashtable in C# that contain unique keys, but not unique values. Is there a way for me to compare the values in the hashtable to check for the ones that are the same? Thanks.
|
|
|
|
|
Yes, you can use the hashtable's Values property to iterate through the collection of values.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
When I code it up, do I need to get the first value and then compare it to the other values as I iterate?
object testvalue = hashtable.value;
while (movenext())
hashtable.value.equals(testvalue);
I am looking for a way to compare the values to each other as I iterate instead of having to specify the value that I am looking for. I you know of any code samples that I can look at, thanks.
|
|
|
|
|
One way to do this is to copy only unique values into an ArrayList . If the size of the array list is < the size of the Values collection, you have duplicates. This seems the most efficient way (single-pass) to check for dupes.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Ravi Bhavnani wrote: One way to do this is to copy only unique values into an ArrayList. If
Or add all values as keys to another Hashtable That will save you quite a bit
|
|
|
|
|
leppie wrote: That will save you quite a bit
Hmmm, actually a Hashtable is more expensive than an ArrayList , so I don't see how it will save you anything, since you can make similar calls (i.e. Contains() vs. ContainsKey() ) to check for membership.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|