Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Run Once and accept parameters

Run Once and accept parameters

Scheduled Pinned Locked Moved Windows Forms
4 Posts 3 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christopher Thornburg
    wrote on last edited by
    #1

    I am working on a POS application that needs to run once, and then when called again it will just activate the current instance. So I have the run once code working but now I need to be able to pass params to the running instance. I am trying to implement a way to save the params to my properties.settings.default.param1, so when the exe is called the second time, I check for an existing instance by name, and if I find it I restore it. before I restore it I save the value of my params, and in the activated event of my form, I grab that data and present it to the user. Well this is not working all the time, sometimes it works sometimes it does not...I'm totally open to new ideas on this process...

    Christopher J. Thornburg Senior Systems Analyst Ideal Card

    J 1 Reply Last reply
    0
    • C Christopher Thornburg

      I am working on a POS application that needs to run once, and then when called again it will just activate the current instance. So I have the run once code working but now I need to be able to pass params to the running instance. I am trying to implement a way to save the params to my properties.settings.default.param1, so when the exe is called the second time, I check for an existing instance by name, and if I find it I restore it. before I restore it I save the value of my params, and in the activated event of my form, I grab that data and present it to the user. Well this is not working all the time, sometimes it works sometimes it does not...I'm totally open to new ideas on this process...

      Christopher J. Thornburg Senior Systems Analyst Ideal Card

      J Offline
      J Offline
      JUNEYT
      wrote on last edited by
      #2

      Please accept my apology I am a bit confused about activating the current instance because you are saying that "run once code working". Therefore, the application is not getting ran for twice. The second attempt to run application will restore to current instance (right?). If you are dealing C# I can't help but in VB. I would use strings in resources of applications where I store these parameters and then recall them back to use. I have copied a sample code from MSDN for you, I tought that it would give you an idea how to save and retrieve parameters from a resource file of an application. Take this please just an idea... :wtf: Imports System Imports System.Resources Imports System.IO Public Class WriteResources Public Shared Sub Main(ByVal args() As String) ' Create a file stream to encapsulate items.resources. Dim fs As New FileStream("items.resources", _ FileMode.OpenOrCreate, FileAccess.Write) ' Open a resource writer to write from the stream. Dim writer = New ResourceWriter(fs) ' Add resources to the resource writer. writer.AddResource("String 1", "First String") writer.AddResource("String 2", "Second String") writer.AddResource("String 3", "Third String") ' Generate the resources, and close the writer. writer.Generate() writer.Close() End Sub End Class

      What a curious mind needs to discover knowledge is noting else than a pin-hole.

      C 1 Reply Last reply
      0
      • J JUNEYT

        Please accept my apology I am a bit confused about activating the current instance because you are saying that "run once code working". Therefore, the application is not getting ran for twice. The second attempt to run application will restore to current instance (right?). If you are dealing C# I can't help but in VB. I would use strings in resources of applications where I store these parameters and then recall them back to use. I have copied a sample code from MSDN for you, I tought that it would give you an idea how to save and retrieve parameters from a resource file of an application. Take this please just an idea... :wtf: Imports System Imports System.Resources Imports System.IO Public Class WriteResources Public Shared Sub Main(ByVal args() As String) ' Create a file stream to encapsulate items.resources. Dim fs As New FileStream("items.resources", _ FileMode.OpenOrCreate, FileAccess.Write) ' Open a resource writer to write from the stream. Dim writer = New ResourceWriter(fs) ' Add resources to the resource writer. writer.AddResource("String 1", "First String") writer.AddResource("String 2", "Second String") writer.AddResource("String 3", "Third String") ' Generate the resources, and close the writer. writer.Generate() writer.Close() End Sub End Class

        What a curious mind needs to discover knowledge is noting else than a pin-hole.

        C Offline
        C Offline
        Christopher Thornburg
        wrote on last edited by
        #3

        Thank you...but that is basically what I am doing...my params save just fine to my resource file...but my "Activated" event is not working they way I thought it would. When I restore the first instance, sometimes I get my data and sometimes its like the Activated event is not even firing!!!! Yeah I'm a C# guy...last basic I wrote was in 1988....hahaha. :)

        Christopher J. Thornburg Senior Systems Analyst Ideal Card

        K 1 Reply Last reply
        0
        • C Christopher Thornburg

          Thank you...but that is basically what I am doing...my params save just fine to my resource file...but my "Activated" event is not working they way I thought it would. When I restore the first instance, sometimes I get my data and sometimes its like the Activated event is not even firing!!!! Yeah I'm a C# guy...last basic I wrote was in 1988....hahaha. :)

          Christopher J. Thornburg Senior Systems Analyst Ideal Card

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          I have written an article that keeps the application only running once. It happens to use windows messaging. You could use this to trigger the running application to check the resource file. http://www.codeproject.com/dotnet/windowsappsingleinstance.asp[^] Hope that helps. Ben

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups