{"id":68384,"date":"2022-04-05T08:00:06","date_gmt":"2022-04-05T06:00:06","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=67196"},"modified":"2022-04-05T10:37:07","modified_gmt":"2022-04-05T08:37:07","slug":"timer-csharp","status":"publish","type":"post","link":"https:\/\/code-maze.com\/timer-csharp\/","title":{"rendered":"Timer in C#"},"content":{"rendered":"<p>In this article, we are going to learn how to use Timer in C#. We can set a timer to generate events following a previously set interval. In addition, the Timer class does this without blocking our program&#8217;s main execution thread.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/dotnet-datetime\/TimersInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2>How Does Timer Work in C#?<\/h2>\n<p>Let&#8217;s see an example of how to use a Timer in C#:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Program\r\n{\r\n    public static void Main(string[] args)\r\n    {\r\n        var timer = new Timer(2000);\r\n        timer.Elapsed += OnEventExecution;\r\n        timer.Start();\r\n\r\n        Console.ReadLine();\r\n    }\r\n\r\n    public static void OnEventExecution(Object? sender, ElapsedEventArgs eventArgs)\r\n    {\r\n        Console.WriteLine($\"Elapsed event at {eventArgs.SignalTime:G}\");\r\n    }\r\n}<\/pre>\n<p>Here, we create an instance of the <code>Timer<\/code> class. We use the constructor to set up a 2000 milliseconds (2 seconds) interval. After that, we use the <code>OnEventExecution<\/code> static method as our event handler and we assign it to the timer&#8217;s <code>Elapsed<\/code> event. Finally, we call the <code>Start()<\/code> method so the events start to fire at the defined interval. Another way to start the timer would be to set the <code>Enabled<\/code> property to <code>true<\/code>.<\/p>\n<p>On execution, we should see the program printing a new line to the console every 2 seconds:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Elapsed\u00a0event\u00a0at\u00a03\/19\/2022\u00a012:20:11\u00a0PM\r\nElapsed event at 3\/19\/2022 12:20:13 PM\r\nElapsed event at 3\/19\/2022 12:20:15 PM<\/pre>\n<p>In other words, our timer raises the elapsed event repeatedly using the interval we set up initially.<\/p>\n<p>If needed, we can stop a timer by calling its <code>Stop()<\/code> method or by setting its <code>Enabled<\/code> property to <code>false<\/code>.<\/p>\n<h2>Generating Recurring Events with Timer in C#<\/h2>\n<p>Any newly created timer will repeatedly raise events once started. That&#8217;s because the timer&#8217;s <code>AutoReset<\/code> property is set to true by default.<\/p>\n<p>However, in a scenario where we only need our timer to raise the <code>Elapsed<\/code> event once we should set the <code>AutoReset<\/code> property to <code>false<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var timer = new Timer(2000);\r\ntimer.Elapsed += OnEventExecution;\r\ntimer.AutoReset = false;  \/\/ Disable recurrent events.\r\ntimer.Start();<\/pre>\n<p>This time the output consists of one line only because the event was triggered once.<\/p>\n<h2>Implementing Handlers<\/h2>\n<p>So far, we&#8217;ve been using explicitly defined methods as event handlers for our timer. However, we have more options to implement our handlers.<\/p>\n<p>Whenever we deal with really simple handlers, we can use lambda syntax to shorten the implementation:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var timer = new Timer(2000);\r\n\r\ntimer.Elapsed += (sender, eventArgs) =&gt;\r\n{\r\n    Console.WriteLine($\"Elapsed event at {eventArgs.SignalTime:G}\");\r\n};\r\n\r\ntimer.Start();<\/pre>\n<p>We can implement asynchronous event handlers as well:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var sw = new StringWriter();\r\nvar timer = new Timer(2000);\r\n\r\ntimer.Elapsed += async (sender, eventArgs) =&gt;\r\n{\r\n    await sw.WriteLineAsync($\"Elapsed event at {eventArgs.SignalTime:G}\");\r\n};\r\n\r\ntimer.Start();<\/pre>\n<h2>Exception Handling<\/h2>\n<p>Whenever a timer event handler throws an exception, the timer component catches it and suppresses it. For instance, the following code won&#8217;t write any exception messages to the console:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var timer = new Timer(2000);\r\n\r\ntimer.Elapsed += (sender, eventArgs) =&gt;\r\n{\r\n    Console.WriteLine($\"Elapsed event at {eventArgs.SignalTime:G}\");\r\n    throw new Exception();\r\n};\r\n\r\ntimer.Start();<\/pre>\n<p>Note that we must never rely on this behavior since it is bound to change in future versions of the .NET Framework.<\/p>\n<p>On the other hand, exceptions raised within asynchronous handlers will not be suppressed by the timer component:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var timer = new Timer(2000);\r\n\r\ntimer.Elapsed += async (sender, eventArgs) =&gt;\r\n{\r\n    await Task.Run(() =&gt; Console.WriteLine($\"Elapsed event at {eventArgs.SignalTime:G}\"));\r\n    throw new Exception();\r\n};\r\n\r\ntimer.Start();<\/pre>\n<p>This time the program will show the error message and exit.<\/p>\n<h2>Disposing Timers<\/h2>\n<p>The Timer component implements the <code>IDisposable<\/code> interface. In most cases, timer instances in our applications will be disposed of automatically when they go out of scope. However, in certain cases, we have to do it manually:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"1\">using (var timer = new Timer(2000))\r\n{\r\n    timer.Elapsed += (sender, eventArgs) =&gt;\r\n    {\r\n        Console.WriteLine($\"Elapsed event at {eventArgs.SignalTime:G}\");\r\n    };\r\n\r\n    timer.Start();\r\n    Console.ReadLine();  \/\/ Avoids ending the timer's scope too soon\r\n}<\/pre>\n<p>We leverage the <code>using<\/code> statement to dispose of our timer once we are done with it.<\/p>\n<h2>Timer and Windows Forms<\/h2>\n<p>Usually, <code>Timer<\/code> calls the <code>Elapsed<\/code> event handler in the system-thread pool. This may not work when the source of the event is a visual Windows Forms component like a Form, a TextBox, or a Button.<\/p>\n<p>To avoid this pitfall, we must set the <code>SynchronizingObject<\/code> property to reference the component that handles the event. This way, our <code>Timer<\/code> will call the event handler in the same thread where the component is located.<\/p>\n<h2>Alternatives to Timer in C#<\/h2>\n<p><code>System.Timers<\/code> and the <code>Timer<\/code> class have been a part of the framework since version 1.1 so it is available in whichever target framework we work with. However, the framework includes other <code>Timer<\/code> classes, each one with a different purpose and behavior.<\/p>\n<p><strong>System.Threading.Timer<\/strong>\u00a0executes a given method a single time after a set interval. The callback method needs to be provided in the constructor and can&#8217;t be changed.<\/p>\n<p><strong>System.Windows.Forms.Timer <\/strong>is\u00a0a Windows Forms component suited for single-thread environments.<\/p>\n<p><strong>System.Web.UI.Timer <\/strong>is part of ASP.NET and performs page postbacks at regular intervals. Only available in .NET Framework.<\/p>\n<h3>Timer vs Stopwatch<\/h3>\n<p><code>Timer<\/code> executes events in a separate thread at a specific user-defined interval. On the other hand, <code>Stopwatch<\/code> runs in our program&#8217;s main thread and measures the elapsed time. <code>Stopwatch<\/code> returns a <code>TimeSpan<\/code> struct containing the elapsed time:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var stopwatch = new Stopwatch();\r\nstopwatch.Start();\r\n\r\nThread.Sleep(100);\r\n\r\nstopwatch.Stop();\r\n\r\nConsole.WriteLine($\"Total milliseconds: {stopwatch.Elapsed.TotalMilliseconds:F4}\"); \/\/ Total milliseconds: 108.8356\r\nConsole.WriteLine($\"Total seconds: {stopwatch.Elapsed.TotalSeconds:F4}\"); \/\/ Total seconds: 0.1088\r\nConsole.WriteLine($\"Total minutes: {stopwatch.Elapsed.TotalMinutes:F4}\"); \/\/ Total minutes: 0.0018<\/pre>\n<p>Although both of these classes work with time, we can clearly see that the <code>StopWatch<\/code> class has a completely different application.<\/p>\n<h3>Third-party Alternatives<\/h3>\n<p>Let&#8217;s have a look at some free third-party libraries that can replace <code>Timer<\/code>. In general, these options offer an array of advanced features in exchange for some added complexity.<\/p>\n<p><a href=\"https:\/\/www.quartz-scheduler.net\/\" target=\"_blank\" rel=\"nofollow noopener\">Quartz.NET<\/a> works embedded in a program or stand-alone. It offers many ways to schedule jobs beyond a simple time interval setup. It can work in clusters, enabling fail-over and load balancing setups.<\/p>\n<p><a href=\"https:\/\/code-maze.com\/hangfire-with-asp-net-core\/\" target=\"_blank\" rel=\"noopener\">Hangfire<\/a> is a job scheduler that tracks jobs in persistent storage ensuring job execution. It schedules jobs based on intervals, like <code>Timer<\/code>, but also offers many more options like job queues or batches.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve learned what Timer in C# is and how it works. We&#8217;ve practiced creating timer event handlers and how to dispose of our timer instances.<\/p>\n<p>We&#8217;ve also learned about the differences between <code>Timer<\/code> and <code>StopWatch<\/code> and, finally, we had a look at some popular third-party alternatives.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to use Timer in C#. We can set a timer to generate events following a previously set interval. In addition, the Timer class does this without blocking our program&#8217;s main execution thread. Let&#8217;s start. How Does Timer Work in C#? Let&#8217;s see an example of how [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[10,1196,1197],"class_list":["post-68384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-net","tag-timer","tag-timer-vs-stopwatch","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Timer in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/timer-csharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Timer in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/timer-csharp\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-05T06:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-05T08:37:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Timer in C#\",\"datePublished\":\"2022-04-05T06:00:06+00:00\",\"dateModified\":\"2022-04-05T08:37:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/\"},\"wordCount\":832,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\".NET\",\"Timer\",\"Timer vs StopWatch\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/timer-csharp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/\",\"url\":\"https:\/\/code-maze.com\/timer-csharp\/\",\"name\":\"Timer in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-04-05T06:00:06+00:00\",\"dateModified\":\"2022-04-05T08:37:07+00:00\",\"description\":\"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/timer-csharp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/timer-csharp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Timer in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Timer in C# - Code Maze","description":"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/timer-csharp\/","og_locale":"en_US","og_type":"article","og_title":"Timer in C# - Code Maze","og_description":"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...","og_url":"https:\/\/code-maze.com\/timer-csharp\/","og_site_name":"Code Maze","article_published_time":"2022-04-05T06:00:06+00:00","article_modified_time":"2022-04-05T08:37:07+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/timer-csharp\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/timer-csharp\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Timer in C#","datePublished":"2022-04-05T06:00:06+00:00","dateModified":"2022-04-05T08:37:07+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/timer-csharp\/"},"wordCount":832,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/timer-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":[".NET","Timer","Timer vs StopWatch"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/timer-csharp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/timer-csharp\/","url":"https:\/\/code-maze.com\/timer-csharp\/","name":"Timer in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/timer-csharp\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/timer-csharp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-04-05T06:00:06+00:00","dateModified":"2022-04-05T08:37:07+00:00","description":"We can set a timer in C# to generate an event after a previously set interval and we can generate recurring events and much more...","breadcrumb":{"@id":"https:\/\/code-maze.com\/timer-csharp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/timer-csharp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/timer-csharp\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/timer-csharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Timer in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=68384"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68384\/revisions"}],"predecessor-version":[{"id":68421,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/68384\/revisions\/68421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=68384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=68384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=68384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}