473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How "Kill" the thread of BackgroundWorker

Hi misters,

Is it possible "kill" the thread of Backgroundworker ?

In my Dowork event, I have NOT While for do e.Cancel = true, only have a
call to external COM.

If I want cancel, calling CancelAsync, not cancels the call to COM.

How I can do it , please ? Any suggestions will be very appreciated.

Thanks in advance.

--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

Aug 12 '08 #1
1 10347
On Mon, 11 Aug 2008 23:37:01 -0700, Alhambra Eidos Kiquenet
<Al*******************@discussions.microsoft.comwr ote:
Hi misters,

Is it possible "kill" the thread of Backgroundworker ?
No, don't do that. The BackgroundWorker runs on a thread pool thread.
It's not nice to kill thread pool threads, even if you could while it's
waiting for a COM call to return (and you usually can't).
In my Dowork event, I have NOT While for do e.Cancel = true, only have a
call to external COM.

If I want cancel, calling CancelAsync, not cancels the call to COM.
It depends on the COM object. Ideally, a COM object would not have a
lengthy or potentially hanging operation that isn't cancellable through
COM itself. Killing threads is a bad idea whether from managed code or
not.

But if you really need to deal with this and can't abort the call to the
COM object directly, I think you're going to have to dedicate a thread you
create for the purpose that you can kill "safely" (not that there's any
truly safe way to kill a thread, but I just mean safer than killing off
thread pool threads).

Note that managed threads don't response to Thread.Abort() unless they are
executing managed code. Any thread stuck in a COM call and which you want
to kill, you're going to have to make sure you have an unmanaged thread
handle that you can kill. As far as I know, the only reliable way to do
this is to call the COM object's method from your own _unmanaged_ thread.
You can either do that via p/invoke or write your own C++/CLI wrapper to
do it.

Basically, if you _really_ need to use thread-killing as a way of aborting
an unmanaged COM object, you're in a pretty ugly situation. I don't think
there's really any _good_ way to solve it.

Pete
Aug 12 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where...
10
by: Jako Menkveld | last post by:
I'm building a relatively simple client-server app. One of the functions of the client is to notify the server when it terminates, this all works fine. The problem comes in when the server is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.