Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# Set timer for viewbag message

Posted on 2016-09-30
2
Medium Priority
?
97 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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