473,699 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to force Thread.Abort() to Abort ?

Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up a
dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is nobody
there to answer the dialog, so I have another thread that calls Abort() on
the first thread in the event that the operation doesn't complete within a
certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box stays
up and the subsequent Thread.Join() hangs until the dialog is cancelled.

Is there any way round this behaviour? This isn't going to happen very often
so I don't care how inefficient it is, but it's got to run on an unattended
server so I can't afford to have my app get stuck forever.

TIA

Andy
Nov 16 '05 #1
13 3487
The abort does not actually get delivered to the managed thread until it
returns from the unmanaged call. There is no way to get around that
behavior.

You could try running the interop call in a separate appdomain, and then
unload the appdomain instead of using an abort. I've observed that the CLR
will go to greater lengths to unload frozen threads when unloading an
appdomain then when you simply call abort.

Another option is to run it in a totally separate process and then unload
the process. You could use remoting between processes to send data
back-and-forth between the main process and the helper process.

In short, there is no good way to shutdown a thread frozen in an unmanaged
call.

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy

Nov 16 '05 #2
A user dialog on a server indicates either poor design or usage of a
component outside of its intended environment. Which of the two can you
repair?

--
Regards,
Alvin Bruney

Shameless Author plug
The Microsoft Office Web Components Black Book with .NET
http://tinyurl.com/27cok
"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy

Nov 16 '05 #3
If your service runs without "desktop interaction" enabled, it's impossible
to get around this issue. If your service runs with desktop interaction
enabled (it shouldn't) you can try to simulate Keyboard input using
SendInput (you have to make sure the dialog got focus), or you can try to
get the Window handle of the Dialog and use SendMessage to simulate a
key-press. The problem of course is "what dialog is there actually
displayed?", you won't press OK on any possible dialog don't you?

This is one of the many reasons you shouldn't try to automate "Office
applications" (or any other interactive application) on a server.

Willy.

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy

Nov 16 '05 #4

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:OT******** ******@TK2MSFTN GP12.phx.gbl...
A user dialog on a server indicates either poor design or usage of a
component outside of its intended environment. Which of the two can you
repair?

I think it's the latter, but I don't see any other option.

I'm trying to convert a word format document to WordProcessingM L. In this
case the user has uploaded a document with a password and word is asking for
the password.

AFAIK there is no other way of converting a .doc to XML other than using
winword.exe. This is the real problem - MS are pushing WordProcessingM L as a
way of processing word documents on the server but it does not offer any
server-side solution to convert to and from .doc format.

From what I can see there is no way to detect if the doc is
password-protected without opening it, and no way to stop word putting up
the dialog.

any other more "out-of-the-box" suggestions would be welcome

Andy
--
Regards,
Alvin Bruney

Shameless Author plug
The Microsoft Office Web Components Black Book with .NET
http://tinyurl.com/27cok
"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops
up a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy


Nov 16 '05 #5
In essence what you are witnessing is one of the reasons why they warn you that Office is not suitable for server side use (theres lots of other reasons too like threading throughput). IIRC correctly, the WordML schema has now been published and generating WordML would be a more scaleable and robust solution than trying to automate word on the server

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

The abort does not actually get delivered to the managed thread until it
returns from the unmanaged call. There is no way to get around that
behavior.

You could try running the interop call in a separate appdomain, and then
unload the appdomain instead of using an abort. I've observed that the CLR
will go to greater lengths to unload frozen threads when unloading an
appdomain then when you simply call abort.

Another option is to run it in a totally separate process and then unload
the process. You could use remoting between processes to send data
back-and-forth between the main process and the helper process.

In short, there is no good way to shutdown a thread frozen in an unmanaged
call.

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 19/01/2005

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #6
Thanks Richard, you understand my problem exactly !!

My application makes extensive use of WordML, and is a model of exactly the
type of thing MS want people to use WordML for. Unfortunately, when the user
uploads a document, I need to convert it from .doc format to WordML so get
the process started. Microsoft doesn't seem to have thought of this part of
it, so the only option open to me is to automate Word.
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:ep******** ******@TK2MSFTN GP14.phx.gbl...
In essence what you are witnessing is one of the reasons why they warn you
that Office is not suitable for server side use (theres lots of other
reasons too like threading throughput). IIRC correctly, the WordML schema
has now been published and generating WordML would be a more scaleable and
robust solution than trying to automate word on the server

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

The abort does not actually get delivered to the managed thread until it
returns from the unmanaged call. There is no way to get around that
behavior.

You could try running the interop call in a separate appdomain, and then
unload the appdomain instead of using an abort. I've observed that the CLR
will go to greater lengths to unload frozen threads when unloading an
appdomain then when you simply call abort.

Another option is to run it in a totally separate process and then unload
the process. You could use remoting between processes to send data
back-and-forth between the main process and the helper process.

In short, there is no good way to shutdown a thread frozen in an unmanaged
call.

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops
up
a dialog box, my thread obviously hangs until the dialog is answered.

Here's the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn't
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn't going to happen very
often so I don't care how inefficient it is, but it's got to run on an
unattended server so I can't afford to have my app get stuck forever.

TIA

Andy


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 19/01/2005

[microsoft.publi c.dotnet.langua ges.csharp]

Nov 16 '05 #7
Hmmm - you are in a bad place basically. Can you get the user to upload in WordML format in the first place? Assuming they do it via http, maybe you could check the content type of the PUT and if it is not text/xml return an error to them so they know what they have done wrong

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Thanks Richard, you understand my problem exactly !!

My application makes extensive use of WordML, and is a model of exactly the
type of thing MS want people to use WordML for. Unfortunately, when the user
uploads a document, I need to convert it from .doc format to WordML so get
the process started. Microsoft doesn't seem to have thought of this part of
it, so the only option open to me is to automate Word.
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:ep******** ******@TK2MSFTN GP14.phx.gbl...
In essence what you are witnessing is one of the reasons why they warn you
that Office is not suitable for server side use (theres lots of other
reasons too like threading throughput). IIRC correctly, the WordML schema
has now been published and generating WordML would be a more scaleable and
robust solution than trying to automate word on the server

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk


Nov 16 '05 #8
Unfortunately that's not an option from a business perspective. we'll have
to have some kind of solution even if it comes down to a robot arm which
presses the escape key every 20 seconds ;-))

current options I'm looking at are (a) using SendKeys; or (b) killing every
copy of winword.exe on the machine. Not what you'd call elegant

Andy

"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:ub******** ******@TK2MSFTN GP09.phx.gbl...
Hmmm - you are in a bad place basically. Can you get the user to upload in
WordML format in the first place? Assuming they do it via http, maybe you
could check the content type of the PUT and if it is not text/xml return
an error to them so they know what they have done wrong

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Thanks Richard, you understand my problem exactly !!

My application makes extensive use of WordML, and is a model of exactly
the
type of thing MS want people to use WordML for. Unfortunately, when the
user
uploads a document, I need to convert it from .doc format to WordML so get
the process started. Microsoft doesn't seem to have thought of this part
of
it, so the only option open to me is to automate Word.
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:ep******** ******@TK2MSFTN GP14.phx.gbl...
In essence what you are witnessing is one of the reasons why they warn
you
that Office is not suitable for server side use (theres lots of other
reasons too like threading throughput). IIRC correctly, the WordML
schema
has now been published and generating WordML would be a more scaleable
and
robust solution than trying to automate word on the server

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Nov 16 '05 #9

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:OG******** ******@TK2MSFTN GP10.phx.gbl...
Unfortunately that's not an option from a business perspective. we'll have
to have some kind of solution even if it comes down to a robot arm which
presses the escape key every 20 seconds ;-))

current options I'm looking at are (a) using SendKeys; or (b) killing
every copy of winword.exe on the machine. Not what you'd call elegant

Andy


Did you look for alternatives that don't require Word at all?
Following a just a few I have used for asp based applications, guess they
offer the same for asp.net too.

http://www.polarsoftware.com/product...rter/index.asp

http://officewriter.softartisans.com...riter-253.aspx

Willy.
Nov 16 '05 #10

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

Similar topics

14
5350
by: Daisy | last post by:
From this page: http://www.c-sharpcorner.com/2/mt_beginner1.asp Thread class's Abort method is called to kill a thread permanently. Make sure you call IsAlive before Abort. if ( thread.IsAlive ) { thread.Abort(); }
18
5847
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this component becomes instabile, throwing a Windows like error (access violation on 0x00000002), not an framework exception. The component and all of its subcomponents are 100% managed code. What could go wrong with Thread.Abort()? Thanks for any hints.
1
4470
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am assuming that this is not an uncommon piece of software. I want to get an architecture that conforms as closely as possible with the recommendations from Microsoft on developing Windows Services, but to be honest I have found difficultly in...
4
1191
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... I am stoping a thread with the following code: Try Thread.CurrentThread.Abort() Catch ex As Exception MessageBox.Show(ex.ToString)
1
1271
by: Nikolay Petrov | last post by:
I have a thread which uses TcpListener to accept new nonnections. I do this in Do/Loop statment The "Do" statment is blocked when the TcpListener waits for new connection. I need a way to signal the thread to aborts itself. If a make the "Do" statement to check with "Do While" or "Do Until", but it is only checked each loop, which happens only when a connection to the TCPListener is made.
2
4284
by: Mark Denardo | last post by:
I'm trying to abort a suspended thread, but I get a ThreadStateException: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in mscorlib.dll Additional information: Thread is suspended; attempting to abort. I have a number or threads in my program - some running, some suspended. I hope I don't have to start the thread up again just to abort it??
7
1470
by: IsRaEl | last post by:
Hello I have a thread that start a really boring process of upload and download a bunch of 1kb files on a server. Since my internet connection SUCKS, during the download process, the class that do the download just freeze..and, since it is ona thread, the service just go on... every time a download starts i save that in a global variable... using that variable, i did some code that detects if the thread is
23
5704
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() { : : do stuff
4
15881
by: Mufasa | last post by:
Is there any way to force a thread to abort and really have it abort? I have a thread that every once in a while gets hung to so I kill it. Problem is I have a thread that every once in a while gets stuck (I'm working on why that happens) and I want to kill it. I do a thread.abort and the status becomes abortrequested but never actually goes through. If it were an actual process I could kill it but there seems to be no real kill for...
0
8686
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
8615
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
8882
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
6533
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
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
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...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.