Results 1 to 10 of 10

Thread: Message Box "OK" Hijacked by Timer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Exclamation Message Box "OK" Hijacked by Timer

    I have a simple Message Box which comes up if the user presses the escape button when looking at a form. In vb6 this worked no problem but in vb.net (I am in the conversion process) it refused to do anything when pressed but would disappear if you press the "X" in the top right hand corner

    After the usual going round in circles I found that this occurred because I have a timer which fires every 100 ms. So, I put "Application.DoEvents()" in the timer and still no joy

    Finally I had to do this:

    Code:
    TimerLayout.Enabled = False
    MsgBox("Blah blah ...", MsgBoxStyle.SystemModal, "MyApp")
    TimerLayout.Enabled = True
    MsgBoxStyle.SystemModal ensures that the Message Box always stays on top (I only discoverd that a few weeks ago after reading many posts saying it cannot be done so that may help somebody)

    So, any comments?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Message Box "OK" Hijacked by Timer

    What exactly is the Timer for?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Re: Message Box "OK" Hijacked by Timer

    Quote Originally Posted by jmcilhinney View Post
    What exactly is the Timer for?
    I have two timers as it happens. They both impinge on the layout and focus when there are multiple copies of the application running - you can consider them as supervisors which check that everything is set up right eg if the user has 8 copies running and closes one, the timers readjust screen layout by looking at the #pragma data_seg in my C++ DLL which keeps track of what the various copies are doing

    Even if there were a way round using timers, this is a conversion from vb6 to vb.net and now is not the time to be making major mods.

    But fundamentally, this is still a strange phenomenon which I would like to understand ... obviously, I have solved the problem but it would be nice to understand why it happens

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Message Box "OK" Hijacked by Timer

    When you say that the button "refuses to do anything", does it REALLY do nothing, or does it appear to click...and nothing happens?

    Aside from that, I would note that MsgBox has been replaced with Messagebox in .NET, but the MsgBoxStyle is not an argument to any overload of Messagebox. Therefore, that functionality supplied by MsgBoxStyle appears to have been left out of .NET. I certainly don't know what that is about, since I never used the functionality in MsgBox, so I can't really miss it. Still, whatever that was doing may have been interacting with the OS in a way that .NET changed. There were a few oddities of that nature in VB6. It seems likely that the result you are seeing has to do with whatever that MsgBoxStyle implementation was in VB6 and how that was ported over to .NET.
    My usual boring signature: Nothing

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Message Box "OK" Hijacked by Timer

    Quote Originally Posted by wavering View Post
    I have a simple Message Box which comes up if the user presses the escape button when looking at a form. In vb6 this worked no problem but in vb.net (I am in the conversion process) it refused to do anything when pressed but would disappear if you press the "X" in the top right hand corner
    ...
    So, any comments?
    Personally, I can't follow that description.
    I read
    1. You are looking at a form and if you press the Escape Key a messagebox should be displayed (which worked in VB6 but not in VB.Net)
    2. it refused to do anything (...so "it" refers to the Escape Key and "refused to do anything" means you see nothing happen, the message box is not displayed).
    3. "but would disappear if you press the "X" in the top right hand corner". What would disappear? You said the message box wouldn't come up, so the only ""X" in the top right hand corner" would presumably be the one on the form the user is looking at, which I'm not sure if that is what you're trying to "disappear".

    So, is the interaction suppose to be, I have a number of forms, I want to remove a form, so I hit the escape key with that form active, a msgbox appears, and I OK the messagebox and it and the form go away, and the screen reorganizes itself because of the removed window?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Message Box "OK" Hijacked by Timer

    Technically, I think your reading of the question is right. Originally, I was going to make a similar post asking what "it" is, since the subject should be the form, but I think it probably is not. I believe that what the OP meant was that the messagebox refused to do anything...though now that I read it again, I'm not so sure.
    My usual boring signature: Nothing

  7. #7
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Message Box "OK" Hijacked by Timer

    If these timers are always running, shouldn't they be running in the background under a different thread? It sounds more like the issue is that you want ansynchronous events to happen, but have put all of the code to run under the same thread. There really should be a background thread that is continuously running to check the forms and screen layout, and a different thread to handle the main "meat" of the program.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Message Box "OK" Hijacked by Timer

    That would probably be a better design, but it is a .NET design. The OP appears to want to do the most minimal conversion from VB6 to .NET as is necessary, and moving to multithreading wouldn't be that.
    My usual boring signature: Nothing

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Message Box "OK" Hijacked by Timer

    Quote Originally Posted by Shaggy Hiker View Post
    Aside from that, I would note that MsgBox has been replaced with Messagebox in .NET, but the MsgBoxStyle is not an argument to any overload of Messagebox. Therefore, that functionality supplied by MsgBoxStyle appears to have been left out of .NET. I certainly don't know what that is about, since I never used the functionality in MsgBox, so I can't really miss it. Still, whatever that was doing may have been interacting with the OS in a way that .NET changed. There were a few oddities of that nature in VB6. It seems likely that the result you are seeing has to do with whatever that MsgBoxStyle implementation was in VB6 and how that was ported over to .NET.
    The .NET implementation of MsgBox actually calls MessageBox.Show internally. That means that anything MsgBox can do, MessageBox.Show can do. Some of those things would require use of Integers where some enumeration values are missing though. It would be interesting to know why there are some things that have been expressly omitted, e.g. MsgBoxStyle.SystemModal. It might have been based on the fact that it was considered to break certain rules or that it was buggy.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Re: Message Box "OK" Hijacked by Timer

    Quote Originally Posted by Shaggy Hiker View Post
    When you say that the button "refuses to do anything", does it REALLY do nothing, or does it appear to click...and nothing happens?
    I click on the OK box of the message box and it appears to click but nothing happens (but if I click on it dozens of times eventually it will work - clearly the 100 ms timer is the problem but why?) But if I click on the "X" on the top right hand side of the message box it immediately proceeds to the next instruction

    Quote Originally Posted by Shaggy Hiker View Post
    Aside from that, I would note that MsgBox has been replaced with Messagebox in .NET, but the MsgBoxStyle is not an argument to any overload of Messagebox. Therefore, that functionality supplied by MsgBoxStyle appears to have been left out of .NET.
    That is my understanding too, which is why I still use MsgBox - it is very useful to always have the Message Box on top (we have all seen apps where the message box disappears underneath a form and you wonder why the app is stalled)

    As for timers running or the app running under a separate thread(s), if I were starting from scratch then probably. But this is a direct conversion from vb6 and by my standards this is a big program - ten months so far converting it

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width