Results 1 to 11 of 11

Thread: Forms.timer of threading.timer?

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Forms.timer of threading.timer?

    Hi.
    I am creating a WMI based app that get processes from multiple machines.
    I have a main MDI form that include forms that run the WMI processes.
    I need a timer to loop every, let's say 3 seconds on every included forms.
    I will be presenting the results in a listview (unless you think there is a better control).
    Now the issue is what timer should I use. The WMI call takes 1 second but I'm not sure on the delay on multiple forms.
    I'm not sure, because every form has it's own timer and call WMI but itself, if a forms.timer will bottleneck and won't be able to show the results smoothy.
    On the other hand, I need to invoke the listview control every time on a thread timer so it will appear on GUI changed, not sure if that stresses all the app.
    If I had just one form then a forms.timer will be fine since I get a straight up usage of the GUI but for multiple form, not so sure.
    Also not sure if WMI will have any benefits from doing a "task" for async calls but that is another question.
    So any ideas?
    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    Re: Forms.timer of threading.timer?

    How many forms? Why not keep the forms timers, then add the results to some global collection, and update the ListView when the collection reaches a certain size?
    A threading timer invoking the Ui repeatedly wouldn’t be beneficial

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    Re: Forms.timer of threading.timer?

    The bottleneck in any case, will be updating the UI

  4. #4

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Forms.timer of threading.timer?

    I lean on keeping a Max of 10 Forms. But 10 forms can be 1 per PC so it is a lot of WMI calling.
    I can't keep a global collection and update , or at least i can't think how to do that because the processes changes in every cycle. I mean the memory consumption, cpu , new processes and that is completely different per PC. So there is no global standard I can think of.

    So a threading timer invoking the UI is not a good idea. Is there any benefit making an async task on WMI and invoking or it's the same?
    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    556

    Re: Forms.timer of threading.timer?

    If you forget for a moment for any UI, including WinForms, you can design much better how you retrieve the data.

    In Pinging multiple machines thread I explained different approach how multiple computers/servers can communicate with the monitoring server.

    So you can create small services running on each machine. The service will retrieve data locally using best methods to do that (and also using local only credentials). This way you will not take care in your monitoring app what user rights you need, how data is retrieved, even what OS is running the machine (Windows, Linux, MacOS or even some IoT devices) and what language is used to write the service.

    When the data is collected locally, lets say every few seconds to reduce stress on the machine, it will send (publish) the data to the listening monitoring server.

    If you use the pub-sub approach I mentioned in the "ping machines" thread, you can set several listening services - one with desktop UI (WinForms), one to perform logging and others according your future needs. Just split the responsibilities into tasks and then into separate applications. This will simplify your global application design.

    Another advantage of pub-sub approach is that you can add more data collecting services that run on more and more machines. Your listener (subscriber) will remain unchanged as it should not care about remote machines, their IPs, domain names or whatever info you will need in the centralized approach with single app.

    About the UI now you can use simple timer that will update the forms. Using concurrent dictionary (check this thread) your subscriber will update dictionaries (key is machine GUID, value is your info object). The timer will run every few seconds and will update only the child forms (or if you choose - user controls added to FlowLayoutPanel). If your data is not updated from previous timer tick, you can skip the update and after some more time you can show that the machine is offline*

    * No more thinking how to implement calls to remote machines and timeouts as you leave data sending to the remote machines

  6. #6
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    556

    Re: Forms.timer of threading.timer?

    Some pseudocode/algos for the different services.

    Client service - data collection and send to monitoring service:
    • Connect to pub-sub server
    • Start timer or new thread for data collection procedure
    • Each few seconds (set to timer or by using Thread.Sleep()) collect the data
    • Serialize the data object (e.g. JSON or some other format like protobuf)
    • Publish to data monitoring channel (e.g. ###MACHINES-MONITOR-123456###)
    • Loop infinitely (if set as windows service) or wait for keypress (if console app)


    Monitoring service - logging (console app or windows service):
    • Connect to pub-sub server
    • Subscribe to monitoring channel ###MACHINES-MONITOR-123456###
    • On each published to that channel message the listener procedure (subscriber) will receive the data as byte array
    • Deserialize the byte array (if required convert byte array to string in case of text formats like JSON)
    • Use the deserialized data object to log data somewhere - file, database or some log service


    Monitoring service - desktop UI app:
    Data communication part
    • Connect to pub-sub server
    • Subscribe to monitoring channel ###MACHINES-MONITOR-123456###
    • On each published to that channel message the listener procedure (subscriber) will receive the data as byte array
    • Deserialize the byte array (if required convert byte array to string in case of text formats like JSON)
    • Use the remote machine GUID to add or update the data in (global or proper accessible level for the subscriber and the UI) concurrent dictionary

    UI part
    • Show main form
    • Start timer that will call procedure that will update the data every few seconds
    • On each timer tick get the data for remote machines from the concurrent
    • For each value in the dictionary do some UI updates (if required). Use the machine GUID to find appropriate user control or child window according your UI design
    Last edited by peterst; Mar 6th, 2021 at 04:25 PM.

  7. #7

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Forms.timer of threading.timer?

    Doing a service per PC is not very practical as there are 200-300 PC's that need to get the service, what I could be doing is push a service on the main servers per domain that communicate with the rest of the computers.
    I have that service set up for another task so I may or may not use it when I check the response times because the problem here would be that I will be pushing the servers hard and they are needed for other jobs concerning the company, now that i think of it, also the individual machines are needed for other jobs, so I prefer to "crash" my machine to death rather than another important one but I'll see the servers behavior...
    I know how to push the data (list is more preferable for not need to worry about similar values for Dictionary), my main concerns are the timer, that I guess I will be using a Forms.Timer and if I will gain any benefit from an Async Task on WMI.
    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    556

    Re: Forms.timer of threading.timer?

    All these monitoring systems can be designed in different way and as always it depends on the specific details. But most times it is easier to install the publisher service on thousands of machines instead of the "main" server to "go" and ask each of them.

    Also it depends if you (as developer) have enough privileges to access these machines.

    In my scenario, where monitoring is performed, there are servers and workstations (users do some heavy and important job there). All are quite powerful (32 gigs of RAM is like the normal workstation) and multi cores/threads so performance is not a big problem. Each machine reports local information, including CPU usage, mem usage, disks usage, UPS status and other services most that can be accessed local only. Other services are exposed publicly - SQL servers, storage servers, etc. But it is always better to check from local app if the service is running and getting its status, aggregate only the useful one, instead of main monitoring server to do many network roundtrips with (mostly) useless data and that multiplied by hundreds machines.

    The other reason to push data instead of pull I've already described - it can be done from every OS and providing really specific device/machine and services information. Many services run on Linux so it is good to know what happens with such machines. .NET Core really made it easy to use single code base but all the info can be returned by anything (OS, language) that can communicate with the pub-sub layer and create the contract data.

  9. #9

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Forms.timer of threading.timer?

    I understand but this is not that kind of a project.
    If I get bloated data then I have a service running on each Domain server(s) that I can extend but that is as far as I'm willing to go.
    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Forms.timer of threading.timer?

    Have you considered the System.Timers.Timer? I know nothing about your server problems, but I understand that the Timers.Timer has the merit of raising its Elapsed event on a separate thread, and you can use lots of them without bothering about the UI. See here for details.

    BB

  11. #11

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: Forms.timer of threading.timer?

    From what I've read thread.timer is considered thread safe but is timers.timer need an invoke to show the UI?I have to test that.
    Like i said I need the UI to be upgraded regularly. So it's either a form.timer or async WMI with threading.timer and then invoking the Ui repeatedly that .paul suggested that is "bad".


    From MSDN:
    System.Timers.Timer: fires an event at regular intervals. The class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.

    System.Threading.Timer: executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed. Like the System.Timers.Timer class, this class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width