Check last commit. Is that what you want?
Threads are creating in Reload() function because we need to have the threads ready anytime. They're creating after skin is loaded.
The Reload() function is called before Update(). Yes, we can create the threads in Update(), but this is irrational and will eat resources because Update can be called too often. The Update() function just starts the threads when we need that, so it don't eat resources.
NOOOPE.
It is currently April 25th, 2024, 3:42 am
[help] C# and multithreading
-
- Posts: 64
- Joined: December 24th, 2012, 6:56 pm
Re: [help] C# and multithreading
Last edited by Aragas on December 20th, 2013, 3:19 pm, edited 1 time in total.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [help] C# and multithreading
Got it... I was just looking at the code, and I think that might just do the trick! I will build it and test it and let you know.Aragas wrote:Check last commit. Is that what you want?
Threads are creating in Reload() function because we need to have the threads ready anytime. They're creating after skin is loaded.
The Reload() function is called before Update(). Yes, we can create the threads in Update(), but this is irrational and will eat resources because Update can be called too often. The Update() function just starts the threads when we need that, so it don't eat resources.
Thanks so much for your help on this. My real goal is to "understand" how this works, mostly so I can create a sample C# plugin for the SDK that demonstrates how to do threading in C# with Rainmeter.
-
- Posts: 64
- Joined: December 24th, 2012, 6:56 pm
Re: [help] C# and multithreading
Nope. The thread terminate itself when all actions in functions are done. Oh..I get it. We don't need to create threads in Reload(). My fault, thanks. Have fixed already.jsmorley wrote: I may just not understand how you are looking at this. Is it that what we are doing is starting a "thread" when the skin is loaded or refreshed, and it just "keeps running" all the time, only terminating if the skin is unloaded or refreshed?
Forget about my last post, only bullshit there
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [help] C# and multithreading
Just one question, I can see that the Dispose() function is cleaning up when the skin is closed, I assume it will do the same when the skin is "refreshed", which I suppose in the context of Rainmeter plugins is pretty much the same as "closing and re-opening" the skin?
-
- Posts: 64
- Joined: December 24th, 2012, 6:56 pm
Re: [help] C# and multithreading
I really want to insist with C# in Rainmeter and with documentation and samples, but i'll understand if you want to do it itself, without help.jsmorley wrote: Got it... I was just looking at the code, and I think that might just do the trick! I will build it and test it and let you know.
Thanks so much for your help on this. My real goal is to "understand" how this works, mostly so I can create a sample C# plugin for the SDK that demonstrates how to do threading in C# with Rainmeter.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [help] C# and multithreading
I'm happy to discuss how we can better document things for the SDK (although we should probably do it for C# and C++ at the same time, and the C++ is really outside my wheelhouse). I agree that while we don't need or want to "teach C# or C++" in the SDK, and reasonable expertise in building code with those languages, and some familiarity with how Rainmeter works under the covers is just required, some better documentation and examples would be good.Aragas wrote: I really want to insist with C# in Rainmeter and with documentation and samples, but i'll understand if you want to do it itself, without help.
Having said that though, I don't think the "templates" we are including is the right place to do that. It should be in some kind of separate documentation.
-
- Posts: 64
- Joined: December 24th, 2012, 6:56 pm
Re: [help] C# and multithreading
Dispose() will stop the thread if skin was closed before thread could stop itself. Hm, i don't know. When is called Finalize()? When skin is closing, right? If Rainmeter don't call Finalize() when we refresh the skin, then no.jsmorley wrote:Just one question, I can see that the Dispose() function is cleaning up when the skin is closed, I assume it will do the same when the skin is "refreshed", which I suppose in the context of Rainmeter plugins is pretty much the same as "closing and re-opening" the skin?
-
- Posts: 64
- Joined: December 24th, 2012, 6:56 pm
Re: [help] C# and multithreading
Yea, i don't know C++ too. I just want to fill the C# documentation. Understanding Rainmeter wasn't easy. I think, writing API methods for C# in wiki would be a good start.jsmorley wrote: I'm happy to discuss how we can better document things for the SDK (although we should probably do it for C# and C++ at the same time, and the C++ is really outside my wheelhouse). I agree that while we don't need or want to "teach C# or C++" in the SDK, and reasonable expertise in building code with those languages, and some familiarity with how Rainmeter works under the covers is just required, some better documentation and examples would be good.
Having said that though, I don't think the "templates" we are including is the right place to do that. It should be in some kind of separate documentation.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [help] C# and multithreading
I'll find out about when Finalize() is called. I don't want to swear to it right now, although I suspect it is called on both an unload and a refresh.
Anyway, I built and tested the code... SUCCESS! As far as I can tell, it works fine. I opened up Process Explorer and watched the threads that Rainmeter was creating and maintaining while the skin was running, unloaded and refreshed, and it seems to work as expected. A new thread is created for a hot heartbeat while it checks the network and / or internet, and then goes away.
Anyway, I built and tested the code... SUCCESS! As far as I can tell, it works fine. I opened up Process Explorer and watched the threads that Rainmeter was creating and maintaining while the skin was running, unloaded and refreshed, and it seems to work as expected. A new thread is created for a hot heartbeat while it checks the network and / or internet, and then goes away.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [help] C# and multithreading
So as far as I can tell Aragas, it seems to work fine.
I have committed the changes to https://github.com/jsmorley/CheckNet, and will update the CheckNet .rmskin in a few minutes so others can try it out.
Thanks once again for your help with this. I think it is pretty clear how it works, and although this code is pretty specific to my functionality, (with only one thread ever being active at a time for instance) it has gone a long way toward helping my understanding.
I owe you a vodka!
I have committed the changes to https://github.com/jsmorley/CheckNet, and will update the CheckNet .rmskin in a few minutes so others can try it out.
Thanks once again for your help with this. I think it is pretty clear how it works, and although this code is pretty specific to my functionality, (with only one thread ever being active at a time for instance) it has gone a long way toward helping my understanding.
I owe you a vodka!