Run Once and accept parameters
-
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
-
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
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.
-
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.
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
-
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
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