0

Sorry, this more than likely has been asked at some point but I'm not even sure what I should be searching on...

I have a winform application with multiple forms. Up until this point having a one form open at a time has been fine. But now, I have a new form that I want to add on but have the ability to keep that form open while I work in other forms. I'm not even sure what this is called but I have seen it done before in other applications.

I did find this: Run two winform windows simultaneously

But this new window is a winpipe queue viewer that runs a thread. When I try initializing using the

Application.Run(new QueueViewer());

I get the error:Starting a second message loop on a single thread is not a valid operation. Use the Form.ShowDialog instead.

The problem with that is it locks the program from doing anything else until I close that form.

Thanks for your help!

Community
  • 1
  • 1
Zonus
  • 2,313
  • 2
  • 26
  • 48
  • 1
    Your question doesn't make much sense - you can show any number of windows independent of each other at any time. Only one of them can have the focus. If this is not what you're trying to do, you should add more detail. The question you linked in describes something you shouldn't attempt. – xxbbcc Nov 07 '14 at 22:50
  • Instead of calling `Application.Run()` and instead of calling the `ShowDialog()` method on the form, just call the `Show()` method. – Peter Duniho Nov 07 '14 at 22:51

1 Answers1

6

Add a form to your project (let's call it Form2). Somewhere within your code (maybe in a button click event) use the following code:

Form2 f = new Form2();
f.Show();  

The Show method allows you to interact with the originating form, whereas ShowDialog prevents interaction from the original form.

MikeH
  • 4,242
  • 1
  • 17
  • 32
  • It appears to work but the window closes right away... Is there a property I need to set to have it stay open? – Zonus Nov 08 '14 at 00:35
  • @ScottJohnson No, this should work as is. Try it with a brand new form that you haven't made changes to and see if the behavior persists. – MikeH Nov 08 '14 at 00:36
  • Still closes right away... I wonder if it has to do with spawning a backgroundworker (in my main window)? – Zonus Nov 08 '14 at 00:50
  • 2
    It should't close right away. Make sure you aren't calling `Close`, `Dispose`, or using a `using` statement. – Matt Jacobi Nov 08 '14 at 04:51
  • @ScottJohnson, I think location of new form is a same as location of main form. Set location ro size of new form different then in main form – Fabio Nov 08 '14 at 06:39
  • Doh. I just realized that it would only be in scope if inside the using statement. I bet that's the problem. Thanks! – Zonus Nov 08 '14 at 14:12
  • Just a FYI, I did remove the using and everything works with it. I thought it should be an easy thing - which are sometimes the hardest things to figure out. Thanks again! – Zonus Nov 08 '14 at 18:29