Avatar of riceman0
riceman0
 asked on

Possible to do *anything* with messagebox?


Hello, in my VB.NET program I continually monitor a serial port and display a status of a connected device, including "disconnected" if we haven't heard anything for a few seconds.

Well, whenever I throw up a modal msgbox I disconnect.  I guess this makes sense because the modal dialog box blocks my form.  However... is there any way to use modal messageboxes in an appllication and continue to handle certain events?  (such as my serial input)

I realize I can create my own forms and display them non-modally, but that is a pain and what I'm trying to avoid.  Besides, I *like* the modal behavior, it's appropriate -- I need the user to make a decision before he/she proceeds.  I just don't want to "disconnect" in the meantime.

Thanks for any thoughts.
.NET ProgrammingVisual Basic.NETC#

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon
AndyAinscow

>>I need the user to make a decision before he/she proceeds.

I don't understand what choice the user has - you are posting some information, namely there isn't a connection.
Maybe you need the MessageBox modal behaviour for some things but a custom, non-modal, information box for other messages.
nepaluz

call the modal ina different thread
riceman0

ASKER
"I don't understand what choice the user has"

For example, Yes/No/Cancel, Ok/Cancel... there are all sorts of options with the MessageBox and the return code is the user choice.

"call the modal ina different thread"

Mind if I ask if you have tried this?  I can think of several different ways to do this and it will end up a research project for sure.  I'd like to hear from someone who has attempted this before I undertake it.



Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
AndyAinscow

>>For example, Yes/No/Cancel, Ok/Cancel... there are all sorts of options with the MessageBox and the return code is the user choice.


Yes I understand that perfectly.

"Serial port is disconnected"  Yes/No/Cancel
??? What use is a choice for that?  It is a message saying the serial port is disconnected.
riceman0

ASKER

The serial port interaction has nothing to do with the messagebox, aside from the fact that they are two things I want to happen at the same time.  The messagebox is shown when the user, for example, opens a data file or confirms some data to be sent to the device.

My VB.NET program is talking to a hardware device (periodic status updates, on a timer).  At the same time it receives status updates from the device and updates a "device status" in the application status bar (which goes to "disconnected" if no messages).

When I show a modal messagebox, all of this stops: both my timer (output -- not sure if its the timer that gets blocked or the serial transmit though) and my serial port events (input), so both the device and my .NET program indicate DISCONNECTED.  I would like to allow serial port activity to continue w/o losing the convenience of modal dialog boxes; they really are useful.  I also want to do so elegantly, it is very possible to make things multithreaded the *wrong* way.

By the way  I am using a System.IO.Ports.SerialPort
AndyAinscow

I think I misunderstood your problem.
If I understand it correctly then you need a custom form that is run modeless and you disable your main form to simulate a modal effect whilst the modeless form is visible.
You could multithread with a normal, modal, MessageBox but that might make some interaction more complex
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mike Tomlinson

Do you have any kind of main processing loop dealing with your serialport?

Please show us some code that deals with sending messages out and also receiving messages.
ASKER CERTIFIED SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
riceman0

ASKER

Well, like I said in the post the reason I'm posting is to see if there was a way to avoid creating custom forms, because modal messageboxes are very convenient, including the modal behavior.  I was hoping there was some way to keep the messagebox from blocking *certain portions* of your application.  I'll leave this open for a bit to see if there is a way, before I fall backto custom modeless forms.
riceman0

ASKER
Will look at that codecruiser.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
riceman0

ASKER

Will try to tease out some code idlemind.
Mike Tomlinson

I'm guessing threading it as CodeCruiser suggests is probably the best solution.

...but it might be possible to "fix" your current code with some tweaks to make it work with the MessageBox.

*Can't really say for sure without seeing more code though*

=)
AndyAinscow

As I said earlier you can fake a modal dialog by displaying a form modeless and disabling the original form.  That means it won't respond to user interaction such as mouse clicks but it does continue processing messages internally - so your current code for the port should keep working away as it currently does.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.