Solved

C# Set timer for viewbag message

Posted on 2016-09-30
2
22 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
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now