none
C# design questions RRS feed

  • Question

  • Hello All:

    I am working on a complicated project for the first time in C#. So far my experience is in Embedded and PLCs. This is the first PC based application with C#. I would like to get some suggestions on good design from the experts. My projects involves multiple objects with different functionalities and executing periodically.

    1. Multiple objects communicating with Modbus TCP devices for every 1 min or every 10 minutes (some objects 1 min and some at every 10 mins)

    2. A scheduler object executing every 5 seconds or so.

    May add more objects... TBD.

    Currently I've designed a prototype with 2 Modbus TCP objects one with 1 Min interval and other 10 minute interval and a scheduler object executing every 5 seconds. I've not used any threads / parallel tasks so far. The prototype is executing fine with no issues.

    But I need to extend this prototype to support more TCP objects. and may be other objects. I don't have any plans to use OPC server as I am not communicating with multiple protocols. I would like to get some inputs on good design techniques to extend this prototype for more objects and get performance efficiency. Any suggestions would be very helpful. Are there any good documentations that can refer? Please provide your inputs.

    Thank you very much in advance,

    Shwetha.

    Friday, June 29, 2018 12:20 PM

Answers

  • The key, I think, is to make things as generic as possible.  Let the scheduler be the master time manager.  Your objects that need periodic service can register themselves with the scheduler, along with their time interval.  The scheduler can then count down the time, and run through its list to see who need to be executed.

    The easy way to do that is to define an interface for ITimerCallback that includes something like a "Run" method, then have your periodic objects derive from that interface.  That way, the scheduler object can just maintain a list with the ITimerCallback and the countdown time.

    Don't worry about performance yet.  If your app is only executing once a minute, performance is not an issue.   Premature optimization is the root of many evils.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Friday, June 29, 2018 9:27 PM
  • Hi Shwegc,

    >> I would like to separate GUI update from the core software. I referred Model View Controller. But that is only for ASP.Net web design. Is there any something similar for C# applications? Please advise.

    Maybe you could consider WPF, which uses the Extensible Application Markup Language (XAML) to provide a declarative model for application programming. for more information, please refer to:

    https://docs.microsoft.com/en-us/dotnet/framework/wpf/getting-started/

    In addition, you could also check WPF MVVM model which like asp.net MVC model.

    https://www.c-sharpcorner.com/UploadFile/raj1979/simple-mvvm-pattern-in-wpf/

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Shwegc Tuesday, July 3, 2018 11:54 AM
    Tuesday, July 3, 2018 2:29 AM
    Moderator

All replies

  • The key, I think, is to make things as generic as possible.  Let the scheduler be the master time manager.  Your objects that need periodic service can register themselves with the scheduler, along with their time interval.  The scheduler can then count down the time, and run through its list to see who need to be executed.

    The easy way to do that is to define an interface for ITimerCallback that includes something like a "Run" method, then have your periodic objects derive from that interface.  That way, the scheduler object can just maintain a list with the ITimerCallback and the countdown time.

    Don't worry about performance yet.  If your app is only executing once a minute, performance is not an issue.   Premature optimization is the root of many evils.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Friday, June 29, 2018 9:27 PM
  • Thank you very much for your inputs!. Also, I would like to separate GUI update from the core software. I referred Model View Controller. But that is only for ASP.Net web design. Is there any something similar for C# applications? Please advise.

    Thanks,

    Shwetha.

    Monday, July 2, 2018 1:57 PM
  • Hi Shwegc,

    >> I would like to separate GUI update from the core software. I referred Model View Controller. But that is only for ASP.Net web design. Is there any something similar for C# applications? Please advise.

    Maybe you could consider WPF, which uses the Extensible Application Markup Language (XAML) to provide a declarative model for application programming. for more information, please refer to:

    https://docs.microsoft.com/en-us/dotnet/framework/wpf/getting-started/

    In addition, you could also check WPF MVVM model which like asp.net MVC model.

    https://www.c-sharpcorner.com/UploadFile/raj1979/simple-mvvm-pattern-in-wpf/

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Shwegc Tuesday, July 3, 2018 11:54 AM
    Tuesday, July 3, 2018 2:29 AM
    Moderator
  • Thank you very much for your inputs!. I will look in to WPF.

    Regards,

    Shwetha.

    Tuesday, July 3, 2018 11:54 AM
  • "Model-View-Controller" is a concept or pattern, not a specific technology.  It can be used in any language.  Even the aged MFC for C++ implemented it.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, July 3, 2018 5:59 PM