|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sub Main is not waiting!!!??My app opens a form and waits for a user to press a button called "Go". If I pass the parameter Q at startup I want it to not show the form but call "Go.PerformClick". So in essence it runs like a console app writing text out to the DOS window that called it. The problem I have is that when Sub Main runs, it works out if the correct parameter has been passed and parses the PerformClick sub but does not execute it and then carries on with the rest of Sub Main before ending the app. See code below: Sub Main(ByVal Args() As String) If Args.Length > 0 Then If Args.GetValue(0) = "Q" Then Console.WriteLine("Fase 3 started: " &Now.ToShortTimeString) Dim newF3 As New Phase3 newF3.Hide() Call newF3.Gop.PerformClick Console.WriteLine("Fase 3 ended: " & Now.ToShortTimeString) Else Dim newF3 As New Phase3 newF3.ShowDialog() End If What am I doing wrong and what do I need to do to force it to wait until the Sub has finished? I even tried putting it in a thread and then using .Join but it even jumps this. Hugh
Show quote
Hide quote
"Hugh Janus" <my-junk-acco***@hotmail.com> schrieb IMO, the approach is not very good. A Form should be used to show something. > OK, > > My app opens a form and waits for a user to press a button called > "Go". If I pass the parameter Q at startup I want it to not show the > form but call "Go.PerformClick". So in essence it runs like a > console app writing text out to the DOS window that called it. > > The problem I have is that when Sub Main runs, it works out if the > correct parameter has been passed and parses the PerformClick sub > but does not execute it and then carries on with the rest of Sub > Main before ending the app. See code below: > > Sub Main(ByVal Args() As String) > > If Args.Length > 0 Then > > If Args.GetValue(0) = "Q" Then > > Console.WriteLine("Fase 3 started: " > &Now.ToShortTimeString) > Dim newF3 As New Phase3 > newF3.Hide() > > Call newF3.Gop.PerformClick > > Console.WriteLine("Fase 3 ended: " & > Now.ToShortTimeString) > > Else > > Dim newF3 As New Phase3 > newF3.ShowDialog() > > End If > > > What am I doing wrong and what do I need to do to force it to wait > until the Sub has finished? I even tried putting it in a thread and > then using .Join but it even jumps this. If you don't intend to show anything, do not create a Form instance. Put the code you currently have in the button's click event into a seperate procedure /outside/ the Form. For example, you can put it into a class and use the Shared modifier, or into a Module. Then, You can call the procedure from the button's click event handler as well as from sub main. Create the Form instance only if no args have been passed. Armin Not really sure what is causing your problem, but I would attack it
thussly. Create a booolean property in your form with an initial value of false. In Sub Main, always dim the form as a new instance. If the command line paremeter is present, set the property to true. Show the form and in the form' Load event, check the property. If true, hide and perform click. typical, I spend ages looking for the solution but can't find it. i
post the question here and then 2 minutes later I work it out. Changing newF3.Go.PerformClick for the following seems to do the trick: Application.Run(newF3) and then: Private Sub Phase3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Hide Call Me.Go_Click(Me, e.Empty) Application.Exit() End Sub But, I still can't get it to write text back to the DOS prompt that called it. Ideas anyone? And once again!!!!! Time to stop posting i think.
change Console.WriteLine("Hello World.") for Console.Out.WriteLine("Hello World.")
Show quote
Hide quote
"Hugh Janus" <my-junk-acco***@hotmail.com> schrieb Application.Run shows the Form. Why do you show a Form if you hide it?> typical, I spend ages looking for the solution but can't find it. i > post the question here and then 2 minutes later I work it out. > > Changing newF3.Go.PerformClick for the following seems to do the > trick: > > Application.Run(newF3) > > > and then: > > Private Sub Phase3_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > Me.Hide > Call Me.Go_Click(Me, e.Empty) In most cases, Application.Exit is not required. Exit all procedures in > Application.Exit() revers order and the thread/process will exit. > End Sub Armin> > > But, I still can't get it to write text back to the DOS prompt that > called it. Ideas anyone? "Hugh Janus" <my-junk-acco***@hotmail.com> schrieb: Check out 'Application.Run' and the 'ApplicationContext' class.> My app opens a form and waits for a user to press a button called "Go". > If I pass the parameter Q at startup I want it to not show the form > but call "Go.PerformClick". So in essence it runs like a console app > writing text out to the DOS window that called it. >[...] > What am I doing wrong and what do I need to do to force it to wait > until the Sub has finished? I even tried putting it in a thread and > then using .Join but it even jumps this. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> its not "waiting" because it is dropping out because there is no message
queue loop. look at the application class and the application.run method Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1142348548.285891.119600@i39g2000cwa.googlegroups.com... > OK, > > My app opens a form and waits for a user to press a button called "Go". > If I pass the parameter Q at startup I want it to not show the form > but call "Go.PerformClick". So in essence it runs like a console app > writing text out to the DOS window that called it. > > The problem I have is that when Sub Main runs, it works out if the > correct parameter has been passed and parses the PerformClick sub but > does not execute it and then carries on with the rest of Sub Main > before ending the app. See code below: > > Sub Main(ByVal Args() As String) > > If Args.Length > 0 Then > > If Args.GetValue(0) = "Q" Then > > Console.WriteLine("Fase 3 started: " > &Now.ToShortTimeString) > Dim newF3 As New Phase3 > newF3.Hide() > > Call newF3.Gop.PerformClick > > Console.WriteLine("Fase 3 ended: " & > Now.ToShortTimeString) > > Else > > Dim newF3 As New Phase3 > newF3.ShowDialog() > > End If > > > What am I doing wrong and what do I need to do to force it to wait > until the Sub has finished? I even tried putting it in a thread and > then using .Join but it even jumps this. > > Hugh >
XML to ODBC
DataView Multiple Change String builder (Parsing vertically presented records) Programming for Touch Screens Sending web email Adding data to database including resource files need help with regular expression Enabling / Disabling Tab Pages generating dev documentation from standard commenting. |
|||||||||||||||||||||||