Solved

C# Set timer for viewbag message

Posted on 2016-09-30
2
57 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 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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.

696 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