Updating UI in C# using Timer

后端 未结 4 1140
孤独总比滥情好
孤独总比滥情好 2020-12-02 02:56

I am working on making my application that reads data from the serial port and updates a gauge on the UI more efficient and I wanted to ask for some advice on my code that

4条回答
  •  没有蜡笔的小新
    2020-12-02 03:47

    It's difficult to answer your question because your asking for "more efficient" rotation of the image is pretty vague. I'm not sure if by more efficient you mean:

    • better performance;
    • less memory usage;
    • or simply less, or more elegant, code

    In any case, unless you are talking about making the code more "elegant" than the only thing that I can come up with is that you could, and probably should, re-use the same image/bitmap. Instead of creating a new one each time you could just clear the one you are using and re-draw your image.

    You might also want to check the refresh rate of your timer that is used to update the UI. A frame rate of about 24 - 30 fps should be enough. Anything more is overkill in this scenario and it will mostly just waste CPU cycles.

    You should also enable double buffering to prevent flickering.

    EDIT

    Based on your comments, it sounds like the problem is not performance but a discrepancy between the interval of the COM port timer and the UI timer. It sounds the timer that updates the UI doesn't run fast enough to detect a change.. What are your intervals?

提交回复
热议问题