?
Solved

C# Set timer for viewbag message

Posted on 2016-09-30
2
Medium Priority
?
67 Views
Last Modified: 2016-11-09
I want a message to show/ change after 5 secs are up (I can do this in java script but I need to do it in C#)

I have a function that starts the timer and it works fine. However how can I change the viewbag message after the 5 sec.
Please show exp. code.

public ActionResult Balance()
        {
            var t = "false";

            SetTimer();

            while (exitFlag == true)
            {
                t = "true";
            }

            ViewBag.Response = t;

            return View();
        }

Open in new window


The Timer function work and it calls the OnTimeEvent ever 5 sec

private void SetTimer()
        {
            // Create a timer with a two second interval.
            System.Timers.Timer aTimer = new System.Timers.Timer(3000);
            // Hook up the Elapsed event for the timer. 
            aTimer.Elapsed += OnTimedEvent;
            aTimer.AutoReset = true;
            aTimer.Enabled = true;
        }

        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            //This does not work.....
            //ViewBag.Response = "true";

            exitFlag = true;
        }

Open in new window


Thx
0
Comment
Question by:quest_capital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 41824040
I can do this in java script
As you should be.

but I need to do it in C#
Not gonna happen. You need to firmly understand the concept of client/server and request/response. Then you will understand why you cannot do this on the server**.

** There is a way that you can kind of do this on the server, but it still entails using Javascript. Look at SignalR for more information.
1

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question