.NET Components for Mobility

Access command line parameters repeatedly

Last post 06-23-2010 3:13 AM by gauravbaadshah. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-22-2010 10:11 AM

    Access command line parameters repeatedly

    Hi

    This may not be directly related to inthehand libraries but I was wondering if this could be possible with the same. I am using VB.net and right now I am accessing command line parameters through the sub Main(args() as String) .ThenI use Application.run(form1) to display my form. However the problem is that my form always runs in the background. So when I use any shortcut to run the application again no command line parameters are passed and instead the form is just brought to foreground.

    Is there any alternative to this using either your libraries or maybe any other workaround to acheive ehat I want to.

    Many thanks in advance.

    GK

  • 06-22-2010 9:27 PM In reply to

    Re: Access command line parameters repeatedly

    This is possible by working around the enforced single-instance behaviour in .NETCF when running on Windows Mobile. See this blog post for details:-

    http://blog.opennetcf.com/afeinman/PermaLink,guid,ec034858-e071-4daa-b1be-0323b7f54b11.aspx

    Once you have done this you can rework the sub Main to manually check to see if your program is running - if it is you can send it the parameters either through a custom windows message or writing to file/registry and signalling a named event or an alternative interprocess communication (IPC) method.

     

    The simplest would probably to use a MessageWindow in your app and set its text to some unique string which identifies your app. P/Invoke FindWindow passing this string constant to get a handle for your running application. If your MessageWindow is not found you use Application.Run to start your app normally. If a valid windows handle is returned you can send it a message (P/Invoke SendMessage or use the Microsoft.WindowsCE.Forms.MessageWindow functions) to notify it and then return from the Main function (don't call Application.Run) to end your second instance. If you want to pass the strings within the message you can use WM_COPYDATA which supports marshalling data between processes. This requires defining the COPYDATASTRUCT which is defined in the SDK headers. If you need more pointers I have examples somwhere but they are probably in C#

    Regards,

    Peter

  • 06-23-2010 3:13 AM In reply to

    Re: Access command line parameters repeatedly

     Hello

    Thanks a ton for the detailed information and workaround.

    However the reason I want to do this in the first place is that .NET CF applications take a few seconds to start that's why I wanted to use only one instance of the application. With the above workaround the application would still run and then notify the previously running instance. This way every time the application is run it will always take time to start. I wanted something that would take less time on the application starting thing.

    Thanks in advance.

    GK

Page 1 of 1 (3 items)
Copyright © 2001-2012 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting