473,395 Members | 1,978 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 can I cancel a thread which is displaying a msgbox ?

I have a thread which is displaying a msgbox. I need to programmatically
cancel the message box if the user does click on OK. I tried to abort
the thread T1.abort() , but am getting an exception. Is there a way to do
this?
Nov 21 '05 #1
5 1563
What exception are you getting?

Presumably, you are getting a ThreadAbortException ;)

Personally, I would NEVER use Abort on a thread. You should just find a
code path to exit the thread. For starters, .NET does not deal with thread
abort while using COM objects very well - and secondly, it's just better to
set a variable in your thread loop to exit.
<milo phipps> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I have a thread which is displaying a msgbox. I need to programmatically
cancel the message box if the user does click on OK. I tried to abort
the thread T1.abort() , but am getting an exception. Is there a way to do
this?

Nov 21 '05 #2
> What exception are you getting?

Presumably, you are getting a ThreadAbortException ;)

Personally, I would NEVER use Abort on a thread. You should just find a
code path to exit the thread. For starters, .NET does not deal with thread
abort while using COM objects very well - and secondly, it's just better to
set a variable in your thread loop to exit.


I am calling msgbox, this means that my thread is not
in my control, so what message loop are you talking about?
Nov 21 '05 #3
? You are creating the message box within the thread? So the thread is
blocked until the user responds to the message box. I'm not sure I
understand why you need to "cancel" the message box. Surely, the message
box dissapears when the user clicks Okay?

<milo phipps> wrote in message news:Or*************@TK2MSFTNGP10.phx.gbl...
What exception are you getting?

Presumably, you are getting a ThreadAbortException ;)

Personally, I would NEVER use Abort on a thread. You should just find a
code path to exit the thread. For starters, .NET does not deal with
thread
abort while using COM objects very well - and secondly, it's just better
to
set a variable in your thread loop to exit.


I am calling msgbox, this means that my thread is not
in my control, so what message loop are you talking about?

Nov 21 '05 #4
> ? You are creating the message box within the thread? So the thread is
blocked until the user responds to the message box. I'm not sure I
understand why you need to "cancel" the message box. Surely, the message
box dissapears when the user clicks Okay?


It would, yes, but I need to cancel the msgbox from the other thread
if a certain something happens (and the user has not pressed "Ok" )
Is that clear now?
Nov 21 '05 #5
It might be easier and cleaner to create a custom message box (just a new
form with some buttons and a Label or TextBox).

Once you have a new MsgBox, you can simply expose a public function in your
new message box to get rid of it.
If your event model is more structured, you may need to allow your MsgBox to
subsribe to events triggered by other modules:

Someone (May not be the MsgBox) defines the event:
Public Event EventYourSubscribingTo()

New MsgBox Handles the event:
AddHandler EventYourSubscribingTo, AddressOf RoutineToDoTheWork

You can trigger your cancellation with an appropriate "RaiseEvent".
RaiseEvent EventYourSubscribingTo


<milo phipps> wrote in message news:uO**************@TK2MSFTNGP12.phx.gbl...
? You are creating the message box within the thread? So the thread is
blocked until the user responds to the message box. I'm not sure I
understand why you need to "cancel" the message box. Surely, the message
box dissapears when the user clicks Okay?


It would, yes, but I need to cancel the msgbox from the other thread
if a certain something happens (and the user has not pressed "Ok" )
Is that clear now?

Nov 21 '05 #6

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

Similar topics

1
by: Dalan | last post by:
Although I have used the code below to suppress the DoCmd cancel action message from appearing on lots of other actions such as preview and print, I have not been able to get to work on a...
2
by: Corrine | last post by:
Is there a way to cancel a change in an option group? The option group still changes to the option clicked on when clicking on the NO button with the following code in the BeforeUpdate event of the...
4
by: Deano | last post by:
Alot of my forms are bound. I would like to offer a Cancel option so that they can make as many changes as they like and still Cancel out without making any changes. I have one idea of how to...
6
by: Arno R | last post by:
Hi all I come across a 'feature' of Access (2000) that I don't like and would like to disable. I am checking if a value already exists in a table. I a subform I use code like : Private Sub...
2
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
1
by: Richard | last post by:
A shipment of material is received. The shipment contains several items. Each item is assigned an internal tracking number for auditing purposes and further processed. The tracking number is...
4
by: Swinky | last post by:
I have added code to delete a record (and records in related tables) in the OnClick property: MsgBox "Confirm delete. Once you confirm, record will no longer exist.", vbOKCancel strSQL =...
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.