473,385 Members | 1,333 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,385 software developers and data experts.

Forcing MessageBox.Show to close from another thread

Fr33dan
57
Hi All,

I'm working on adding a message box method that will allow me to display a message to the user without waiting for the user to answer. I've done this by starting MessageBox.Show in a separate thread.

I also use a static DialogResult variable to allow me to see the user's result in my calling code. My method also accepts a MessageBoxButtons parameter that is then passed on to the MessageBox.Show method.

The only problem is that I will need to close the box later on by calling another method. I've tried Thread.Abort and Thread.Interrupt but neither close the dialog.

Here is my current code for clarity (all contained in static Log):
Expand|Select|Wrap|Line Numbers
  1. public static void writeMessage(string LogType, string Error, MessageBoxButtons buttonSet)
  2. {
  3.     MessageData data = new MessageData();
  4.     data.message = Error;
  5.     data.LogType = LogType;
  6.     data.buttons = buttonSet;
  7.     messageThread = new Thread(new ParameterizedThreadStart(Log.displayMessage));
  8.     messageThread.Start(data);
  9. }
  10.  
  11. public static void closeMessage()
  12. {
  13.     messageThread.Interrupt();
  14. }
  15.  
  16. private class MessageData
  17. {
  18.     public string message;
  19.     public string LogType;
  20.     public MessageBoxButtons buttons;
  21. }
  22.  
  23. private static void displayMessage(object data)
  24. {
  25.     MessageData d = (MessageData)data;
  26.     Log.lastMessageResult = DialogResult.None;
  27.     Log.lastMessageResult = MessageBox.Show(d.message, d.LogType, d.buttons);
  28. }
I haven't written any code that uses this yet so if anyone also has any ideas on how to get the same functionality in a different fashion please that could be helpful as well.

Thanks in advance,
Fr33dan
May 15 '09 #1
3 5093
Plater
7,872 Expert 4TB
You're already doing most of the work, just make your own dialog form then?
May 15 '09 #2
Fr33dan
57
I considered that but I'm afraid it would become unnecessarily complex when trying to implement the various button sets.
May 15 '09 #3
tlhintoq
3,525 Expert 2GB
Not really. I did my own messagebox control that includes parameters such as an int for how many seconds until autoclosing. This way I can pass text, icon and 25 to have it auto close after 25 seconds for example.
May 15 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
4
by: Tressa | last post by:
I have a messagebox that I only want to pop up only if it is not already being displayed on the screen. My code is still poping up the messagebox even though it is on the screen. What am I doing...
7
by: Pi | last post by:
I have an MDI parent with one or more children forms. Each child form has an engine thread that processes data. The child form's _Closing event is roughly 01 Private Sub...
1
by: Pi | last post by:
I have an MDI parent with one or more children forms. Each child form has an engine thread that processes data. The child form's _Closing event is roughly 01 Private Sub...
4
by: Larry Woods | last post by:
I have a Messagebox that looks like: MessageBox.Show("There are pending changes for this patient. Do you want to continue to close?", "Pending Changes", MessageBoxButtons.YesNo,...
2
by: Nuno Magalhaes | last post by:
Why does the MessageBox.Show function in the thread below changes the program behaviour, in other words, the APListView becomes filled with values with a call to RefreshAPListView. Without the...
1
by: Jeff Waskiewicz | last post by:
Hello All, I'm trying to solve a nagging problem. The goal is to draw a rectangle over the top of all the other controls on a form. Specifically, over a ChartFX control. The user would draw...
1
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
How can I kill or close a MessageBox that is shown in a thread that I later abort? In the following code, the MessageBox will always stay open until closed by the user, even when the other event...
2
by: Risa | last post by:
hi, i created a windows application that uses winsock control. in the closing event, it sends a "Disconnect" string message. the server (listening application) does not receive this message. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.