Passing Parameters to a running thread
-
Okay, I am trying to implement a way to pass parameters to an already running thread or application. I have added some "Run Once" logic to an application of mine and it works great, if you try to load it twice...it looks for the thread by name, and if it finds it it just activates it. It works great...BUT...I want to pass 2 params to the running thread and this is how I am doing it and it is not working...not totally. So once my app is running, I will call the exe again and pass 2 params to it, when the second instance tries to start, I receive the params and save them to my properties.settings.default.variable1, variable2. then save the settings, check my thread, and if its running I just activate the running thread and exit. When the activated event fires I then look at the value of my properties.settings.default.whatever and the data has not changed, BUT if I exit the app at that point and start it again...the values have changed. Its like the running thread has a different session of the data open and it dosen't see the changes. So my question is: Is there a way to refresh the data session of the properties.settings stuff so I can see the last changes made??? or is there another way to pass the params to my running thread from the started thread???? Thanks...
Christopher J. Thornburg Senior Systems Analyst Ideal Card
-
Okay, I am trying to implement a way to pass parameters to an already running thread or application. I have added some "Run Once" logic to an application of mine and it works great, if you try to load it twice...it looks for the thread by name, and if it finds it it just activates it. It works great...BUT...I want to pass 2 params to the running thread and this is how I am doing it and it is not working...not totally. So once my app is running, I will call the exe again and pass 2 params to it, when the second instance tries to start, I receive the params and save them to my properties.settings.default.variable1, variable2. then save the settings, check my thread, and if its running I just activate the running thread and exit. When the activated event fires I then look at the value of my properties.settings.default.whatever and the data has not changed, BUT if I exit the app at that point and start it again...the values have changed. Its like the running thread has a different session of the data open and it dosen't see the changes. So my question is: Is there a way to refresh the data session of the properties.settings stuff so I can see the last changes made??? or is there another way to pass the params to my running thread from the started thread???? Thanks...
Christopher J. Thornburg Senior Systems Analyst Ideal Card
If I am understanding your problem correctly, what is needed is to have a data location where the modifications are made and the thread can access the data. This should eliminate the need for parameters. Keep in mind that when multiple threads are accessing a data location, it should be protected in such a way that only one thread can access/modify the data at a time. Phil
-
If I am understanding your problem correctly, what is needed is to have a data location where the modifications are made and the thread can access the data. This should eliminate the need for parameters. Keep in mind that when multiple threads are accessing a data location, it should be protected in such a way that only one thread can access/modify the data at a time. Phil
Such as writing the params to a text file and then reading them in duing the activate event of the form???
Christopher J. Thornburg Senior Systems Analyst Ideal Card
-
Such as writing the params to a text file and then reading them in duing the activate event of the form???
Christopher J. Thornburg Senior Systems Analyst Ideal Card
-
Okay, I am trying to implement a way to pass parameters to an already running thread or application. I have added some "Run Once" logic to an application of mine and it works great, if you try to load it twice...it looks for the thread by name, and if it finds it it just activates it. It works great...BUT...I want to pass 2 params to the running thread and this is how I am doing it and it is not working...not totally. So once my app is running, I will call the exe again and pass 2 params to it, when the second instance tries to start, I receive the params and save them to my properties.settings.default.variable1, variable2. then save the settings, check my thread, and if its running I just activate the running thread and exit. When the activated event fires I then look at the value of my properties.settings.default.whatever and the data has not changed, BUT if I exit the app at that point and start it again...the values have changed. Its like the running thread has a different session of the data open and it dosen't see the changes. So my question is: Is there a way to refresh the data session of the properties.settings stuff so I can see the last changes made??? or is there another way to pass the params to my running thread from the started thread???? Thanks...
Christopher J. Thornburg Senior Systems Analyst Ideal Card
You can make a static class that exposes properties that you can set/get from different threads. So when your activated event fires the thread will get the value of the property. Because you are using a multi-threading application the static properties should use
lock {...}
inside the get/set. -
Okay, I am trying to implement a way to pass parameters to an already running thread or application. I have added some "Run Once" logic to an application of mine and it works great, if you try to load it twice...it looks for the thread by name, and if it finds it it just activates it. It works great...BUT...I want to pass 2 params to the running thread and this is how I am doing it and it is not working...not totally. So once my app is running, I will call the exe again and pass 2 params to it, when the second instance tries to start, I receive the params and save them to my properties.settings.default.variable1, variable2. then save the settings, check my thread, and if its running I just activate the running thread and exit. When the activated event fires I then look at the value of my properties.settings.default.whatever and the data has not changed, BUT if I exit the app at that point and start it again...the values have changed. Its like the running thread has a different session of the data open and it dosen't see the changes. So my question is: Is there a way to refresh the data session of the properties.settings stuff so I can see the last changes made??? or is there another way to pass the params to my running thread from the started thread???? Thanks...
Christopher J. Thornburg Senior Systems Analyst Ideal Card
Use: Thread.Start(object) method as: public void Start ( Object parameter ) where you pass a static or a dynamic but(reference is kept to prevent garbage collection "WeakReference can also be considered for this case") object which includes your parameters that you can change while the thread is running. ALSO, searching a Thread by it's name is not preferred, try keeping a reference to each thread you create, better an integer value or byte(if you don't have more than 255 threads in your application ;) ) and access these threads with these indexes. You can also use a Dictionary, anyway. As a result you can modify your parameters in the objectargument you pass and also keep a reference of in you main thread. BUT, be careful chosing and a using a type for your object argument. If you are using value types, modify the real data accessing it through "ref" keyword.