Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I've created a windows application project, when you run the application it doesn't show a form straight away i run Application.Run on a ApplicationContext which makes a WCF service connection to a WCF server, the server can call methods on the windows application i've created because i'm using a duplex connection, when the server calls a method on the service consumer it does Application.Run(new Form1) passing in a form, the first time the wcf server does it, it works fine but the second time the form doesn't show, can anyone tell me why this is happening is it because i've already called Application.Run once already ?
Posted
Updated 24-Feb-11 1:46am
v2

From MSDN:
"This method adds an event handler to the mainForm parameter for the Closed event. The event handler calls ExitThread to clean up the application"

See the link:
http://msdn.microsoft.com/en-us/library/ms157902.aspx[^]

So you can't call it more that once.
 
Share this answer
 
Comments
Member 7654832 24-Feb-11 8:33am    
ok so if i just have Application.Run would that work then?
Olivier Levrey 24-Feb-11 8:57am    
Yes, just call it once, and it will be ok. If you want to display 2 forms (one after another one) then you may do something like:
new Form1().ShowDialog();
Application.run(new Form2());
Sergey Alexandrovich Kryukov 24-Feb-11 15:39pm    
Great, my 5.
--SA
Why can't you run a form that's initially hidden, and then show it (or another appropriate form) when you're ready?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:39pm    
Best options in my view, my 5.
Why having all that troubles for very questionable functionality.
--SA
Call the parameter-less version of Application.Run so your message loop is up and running. Now in your WCF callback handler, show a new form. You will have to manually handle application termination though.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:38pm    
It should work, my 5, but avoiding all of this, as John suggested is much better.
--SA
Nish Nishant 24-Feb-11 15:43pm    
I answered after the OP replied to John saying that he did not want to do that because the form apparently is heavy and consumes too much memory. So he wants to show it only when he has to.
Nish Nishant 24-Feb-11 15:44pm    
Thanks SA!
I don't want my application to take up to much memory so i'm only launching when i have to, instead of making the window hidden then showing because the window object still exists
 
Share this answer
 
Comments
#realJSOP 24-Feb-11 8:38am    
Use the Add Comment link under the answer you want to reply to.
#realJSOP 24-Feb-11 8:40am    
That's an arbitrary and pointless requirement. If you're probably going to display the form anyway, just go ahead and display it. You've already loaded the namespaces required for the form, so you're not saving anything.
Member 7654832 24-Feb-11 9:19am    
but i might not display the form so by not doing Application.Run on the form would sureley save some memory?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900