Windows Form App C# 10.0 I want to use Stopwatch to record Process calls Elapsed times in a Rich Text Box "event log"

Steven Brewer 0 Reputation points
2025-11-26T00:09:35.56+00:00

I have a application that I am updating for work, and I have two processes, one is a csv writer and another a rest API call I want to record the time it takes for the processes to run then display each individual elapsed time in a rich text box I am using for an event log. (we cant have an actual event log because pretty much all users don't have admin privileges). I also want to add further information including from message boxes if possible if not Ill just add additional messaging. This is an application that I inherited and the original author has sense retired.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Susmitha T (INFOSYS LIMITED) 1,630 Reputation points Microsoft External Staff
    2025-11-26T07:51:18.51+00:00

    Thanks for reaching out!

    You can use Stopwatch in C# to measure how long each process takes, then append the elapsed time into a Rich Textbox that acts as your event log. Stopwatch gives accurate timing for any operation, such as your CSV writer and REST API call.

    After each process finishes, you simply write the elapsed time into your RichTextBox, which you are already using as an event log. This works for users without admin access, since it does not require the Windows Event Log.

    You can also log additional details like results from MessageBox prompts or any custom status messages by appending text into the same RichTextBox

     The overall flow is:

    1.Start a Stopwatch

    2.Run the process (CSV write/ API call)

    3.Stop the Stopwatch

    4.Append a log entry into the RichTextBox with the time taken.

    5.Add any custom message you want.

    This keeps all your timing information and messages in one place and avoids the need for elevated permissions.

     

    References: Stopwatch Class (System.Diagnostics) | Microsoft Learn

    RichTextBox Class (System.Windows.Forms) | Microsoft Learn

     

    Let me know if you need any further help with this. I will be happy to assist.

    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.