# Dialog component with timer

**URL:** <https://forum.radzen.com/t/dialog-component-with-timer/6946>\
**Category:** Blazor Server\
**Created:** [March 3, 2021, 8:12pm UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946 "2021-03-03T20:12:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![can\_altunoz](https://forum.radzen.com/user_avatar/forum.radzen.com/can_altunoz/32/6168_2.png) [@can\_altunoz](https://forum.radzen.com/u/can_altunoz)\
**Post date:** [March 3, 2021, 8:12pm UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/1 "2021-03-03T20:12:49Z")

</div>

Hi there,  
First of all thanks for amazing components. Im new in blazor, is there any posibility to make dialogbox with timeout ? For an example dialogbox with accept and cancel button and count down timer from 5 sec.  
After count down finish i want to close dialogbox.  
Thanks

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 4, 2021, 6:09am UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/2 "2021-03-04T06:09:40Z")

</div>

Hi @can_altunoz,

Yes, this is possible. You can create a timer and use the Close method of the Radzen DialogService to close the current dialog. You can search the forum for examples how to use a timer in a Blazor application.

---

<div class="post-metadata">

**Author:** ![can\_altunoz](https://forum.radzen.com/user_avatar/forum.radzen.com/can_altunoz/32/6168_2.png) [@can\_altunoz](https://forum.radzen.com/u/can_altunoz)\
**Post date:** [March 4, 2021, 7:12am UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/3 "2021-03-04T07:12:25Z")

</div>

Hi korchev ty for info but i cant find any examples or tutorials in forum ☹ can u give me a link pls . Thanks

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 4, 2021, 7:54am UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/4 "2021-03-04T07:54:51Z")

</div>

You can explore the [search results](http://forum.radzen.com/search?q=timer).

---

<div class="post-metadata">

**Author:** ![can\_altunoz](https://forum.radzen.com/user_avatar/forum.radzen.com/can_altunoz/32/6168_2.png) [@can\_altunoz](https://forum.radzen.com/u/can_altunoz)\
**Post date:** [March 4, 2021, 9:13am UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/5 "2021-03-04T09:13:47Z")

</div>

Dear @korchev,  
Like as you said i searched all forum links but still cant find any example...There is no countdown or timer example with any component init. Anyway ty

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 4, 2021, 9:18am UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/6 "2021-03-04T09:18:47Z")

</div>

Yes, there isn't exactly the same thing as you need. However the links show how to use a timer. Use it as a basis of your countdown implementation.

---

<div class="post-metadata">

**Author:** ![Developer](https://forum.radzen.com/user_avatar/forum.radzen.com/developer/32/6174_2.png) [@Developer](https://forum.radzen.com/u/Developer)\
**Post date:** [March 4, 2021, 7:20pm UTC](https://forum.radzen.com/t/dialog-component-with-timer/6946/7 "2021-03-04T19:20:31Z")

</div>

Hey @can_altunoz,

You can do this easily like this:

```auto
@result
                <RadzenButton Click="@((args) => OpenDialog(args))" />

                @code{

                    string result;
                    Task<bool?> response;
                    void OpenDialog(object args)
                    {
                        System.Timers.Timer timer = new System.Timers.Timer();
                        timer.Interval = 3000; // 3 secs in milliseconds
                        timer.Elapsed += OnTimedEvent;
                        timer.AutoReset = false;
                        timer.Enabled = true;

                        response = DialogService.Confirm("Are you sure?", "Confirmation", new ConfirmOptions()
                        {
                            OkButtonText = "Yes",
                            CancelButtonText = "No"
                        });

                    }

                    void DoSomething()
                    {
                        // Nothing clicked
                        if (response.Result == null)
                        {
                            result = "didnt clicked anything";
                        }
                        else if (response.Result == true)
                        {
                            result = "clicked yes!";
                        }
                        else
                        {
                            result = "clicked no!";
                        }
                    }

                    private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
                    {
                        InvokeAsync(() =>
                        {
                            DialogService.Close();
                            DoSomething();
                            StateHasChanged();
                        });
                    }
                }

```

Hope it helps 😉
